Page 1 of 1

customize folder permissions

PostPosted:Thu Feb 25, 2010 1:12 pm
by blindrood
I would like to do simillar change described in http://forum.openkm.com/viewtopic.php?f=4&t=3072
but with folder permissions
I would like to allow to change folder permissions only for admin and author of this folder

So I found place where I Should do this
at TabFolder.java there is this code
Code: Select all
	public void setProperties(GWTFolder folder) {
		this.folder.set(folder);
		security.setPath(folder.getPath());
		security.GetGrands();
		if ((folder.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE) {
			security.setChangePermision(true);
		} else {
			security.setChangePermision(false);
		}
	}
as I understand I should change if statement to something like
Code: Select all
if(Main.get().workspaceUserProperties.getWorkspace().isAdmin() || something.isAuthor() )
but I didn't figure out what this 'something' should be
any help?


EDIT
ok so I found this
Code: Select all
if ( folder.getAuthor().compareTo(Main.get().workspaceUserProperties.getUser() == 0 || Main.get().workspaceUserProperties.getWorkspace().isAdmin() )
is that correct?

Re: customize folder permissions

PostPosted:Thu Feb 25, 2010 4:26 pm
by jllort
The security is controled in ToolBar.java not in TabFolder.java, all permissions are controled there.

The author ir right
Code: Select all
folder.getAuthor()
And if is in admin role too
Code: Select all
Main.get().workspaceUserProperties.getWorkspace().isAdmin()
Take a look all methods checkToolButtomPermissions ( folders, mails, documents, etc... ), here is the place where you must do the changes
Code: Select all
public void checkToolButtomPermissions(GWTFolder folder, GWTFolder folderParent, int originPanel)
In OpenKM we'll change it, adding more roles by default that will solve this problems.

Re: customize folder permissions

PostPosted:Mon Mar 01, 2010 11:40 am
by blindrood
I'm trying to find where in this method I should change it but can't find.

I want to give permission of using Update button at security tab on folders for its author and admin
and i can't see where in checkToolButtomPermissions method i can do such change.

Re: customize folder permissions

PostPosted:Mon Mar 01, 2010 6:15 pm
by jllort
That's other question. Then you must take a look at Document.java class into package es.git.openkm.frontend.widget.properties

There's the button you're looking for.

Re: customize folder permissions

PostPosted:Tue Mar 02, 2010 9:39 am
by blindrood
Actually I did some digging and I can't agree with You.

this button is created at SecurityScrollTable class

This class is never used at Document.java
But it is used at TabFolder.java (as I meant at first post) as object called 'security'

This button is activated using setEnabled method
which is used in setChangePermission method of SecurityScrollTable class
which is modified by SetProperties method of TabFolder class

so I changed code of SetProperties method to avoid giving access to this button for other users

I have to persist with my way and it actually works but I'm still not sure if it's not breaking any other code.

of course I might be wrong :) (or there is still some misunderstanding of my problem)

Re: customize folder permissions

PostPosted:Tue Mar 02, 2010 9:03 pm
by jllort
Upss I had I bad day when I wrote it :) really I might revise my own code and not use my memory by default , sorry.


1- You're right ( securityScrollTable is where's the button )

here there's two interesting methods
Code: Select all
	public void setVisibleButtons(boolean visible){
		button.setVisible(visible);
	}

and 

	public void setChangePermision(boolean permission) {
		button.setEnabled(permission);
	}
Don't worry for set visible is used to disable change permission is trash view for example.

In tabDocument is where you must make some changes if you want to change button to documents:
Code: Select all
if ((doc.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE && !doc.isCheckedOut() && !doc.isLocked()) {
			security.setChangePermision(true);
		} else {
			security.setChangePermision(false);
		}
here must be added in conditional the test if users is same as owner.

Must be something like this
Code: Select all
if (((doc.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE || 
			 Main.get().workspaceUserProperties.getUser().equals(doc.getAuthor()) ) 
			 && !doc.isCheckedOut() && !doc.isLocked()) {
			security.setChangePermision(true);
		} else {
			security.setChangePermision(false);
		}
The question is mantaining that when a node is checkout or locked can not be changed the permissions.

The tabFolder is similar to change button permission:
Code: Select all
if ((folder.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE) {
			security.setChangePermision(true);
		} else {
			security.setChangePermision(false);
		}
to
Code: Select all
if ((folder.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE || || 
			 Main.get().workspaceUserProperties.getUser().equals(folder.getAuthor()) {
			security.setChangePermision(true);
		} else {
			security.setChangePermision(false);
		}
In both change could be some problem if after creating folder or document write permissions to author are deleted. Simply OpenKM then when you'll try to change permission will fire some error.

Hope it help you

Re: customize folder permissions

PostPosted:Mon Mar 08, 2010 8:10 am
by blindrood
Thanks for the code. It is working fine.

I'm still making more permission changes

I managed to enable remove/rename button only for Author and it works at mainmenu and topmenu but other users still have those rights by using contextmenu

How can I change the code for this?

Re: customize folder permissions

PostPosted:Tue Mar 09, 2010 9:50 am
by jllort
This sure must be changed in ToolBar.java

In toolbar.java in concentrate the security evaluation. There are three methods ( folder, document, mail ), take look there specially where is assigned the enabledelete() and disabledelete()

Re: customize folder permissions

PostPosted:Wed Mar 10, 2010 8:35 am
by blindrood
I can not find specific code for context menu at ToolBar.java
keyword 'enabledelete' appears only few times
once for folder (I made changes)
once for document (I made changes)
once for mail (I disabled mail as it is not useful, for now at least)
once for evaluateShowIcons (I'm not sure what id does yet)
and once for definition of this method

I just don't understand why it works for toolbar buttons but not for context menu

Re: customize folder permissions

PostPosted:Wed Mar 10, 2010 12:03 pm
by jllort
it's the same case.

You must modify folder, document or mail method in concordance to enable or disable button with your new security logic ( similar if case than other ).

Re: customize folder permissions

PostPosted:Wed Mar 10, 2010 2:30 pm
by blindrood
This is my code for toolbar.java
http://www.wklej.eu/index.php?id=1f76751ae9
those little changes I made (like at 696 line) works for toolbar and main menu
but context menu still gives possibility to delete/move/rename files/folders

Re: customize folder permissions

PostPosted:Wed Mar 10, 2010 4:21 pm
by jllort
OK for it you must edit TaxonomyMenu from package com.openkm.frontend.client.widget.taxonomy and take a look the method
Code: Select all
 public void checkMenuOptionPermissions(GWTFolder folder, GWTFolder folderParent) 

Re: customize folder permissions

PostPosted:Thu Mar 11, 2010 8:24 am
by blindrood
Thanks for this information
I customized this method and context menu works correctly but only for folders
and as I can see, method for documents
Code: Select all
public void checkMenuOptionPermissions(GWTDocument doc, GWTFolder folder)
is empty ;-)
So now my question is: where is code for documents context menu? It surely works somehow :)


EDIT:
found it :D
es.git.openkm.frontend.client.widget.filebrowser.menu.TaxonomyMenu
Permissions works now as I wanted to :D
thankyou very much for help :)

Re: customize folder permissions

PostPosted:Fri Mar 12, 2010 9:34 am
by jllort
There's other taxonomyMenu but in filebrowser package ( look for taxonomyMenu.java and you'll get two classes CTRL+SHIFT+R in eclipse )