Page 1 of 1

Automation Scripts and Repository View in OpenKM 6.2.2

PostPosted:Mon Feb 11, 2013 1:54 pm
by armber
Hello Everyone,

working with OpenKM Version: 6.2.2 (build 7815), I would like to implement a procedure that when a Document is moved to a Folder (e.g. for any folder that includes "Official" in the path) automatically removes all rights - except Read right - to all users and roles that have rights on it.

I found a clue that suggests to specify an automation script using the "Administration > RepositoryView" function, however (ever working as an Administrator) I could not find this function in version OpenKM 6.2.2.

Can anyone confirm that RepositoryView function is still available in version 6.2.2 and clarify how to access it?
Also, any suggestion for a practical way to implement the transformation to "read-only" of all Documents that are moved in a ".../Official/.." folder would be more than appreciated!

Many thanks,
Armando

Re: Automation Scripts and Repository View in OpenKM 6.2.2

PostPosted:Tue Feb 12, 2013 10:57 pm
by jllort
Repository view is not still available in version 6.2.2 althought we have been working on it for nearly release. Anyway what you need is automation http://wiki.openkm.com/index.php/Automation . You can do with it, the automation idea is firewall idea -> validation ( when folder will be like ) and execute some action ( move -> shoulb be implemented using OKMFolder api)

Re: Automation Scripts and Repository View in OpenKM 6.2.2

PostPosted:Wed Feb 13, 2013 2:36 pm
by armber
jllort,
thank you very much for your answer.

I found the reference to the 'Repository View' feature in the WIKI, however I probably didn't note the disclaimers concerning limited sw version validity .

Wanting to follow your suggestion to implement the functionality, I would really appreciate if you could provide a feedback about the correctness of use of the following script as ExecuteScripting action in a OpenKM community version installation:
Code: Select all
import java.util.Map;
import com.openkm.api.OKMAuth;
import com.openkm.bean.Permission;
 
if (eventType.equals("CREATE_DOCUMENT")) {
	String userId = session.getUserID();
	String path = eventNode.getPath();
	OKMAuth oKMAuth = OKMAuth.getInstance();
 
	// All Roles only will continue having read grants
	Map hm = oKMAuth.getGrantedRoles(null, path);
	for (String roleName : hm.keySet()) {
		oKMAuth.revokeRole(null, path, roleName, Permission.WRITE, false);
		oKMAuth.revokeRole(null, path, roleName, Permission.DELETE, false);
		oKMAuth.revokeRole(null, path, roleName, Permission.SECURITY, false);
	}
 
	// All users only will continue having read grants
	hm = oKMAuth.getGrantedUsers(null, path);
	for (String userName : hm.keySet()) {
		if (!session.getUserID().equals(userName)) {
			oKMAuth.revokeUser(null, path, userName, Permission.WRITE, false);
			oKMAuth.revokeUser(null, path, userName, Permission.DELETE, false);
			oKMAuth.revokeUser(null, path, userName, Permission.SECURITY, false);
		}
	}
}
Many thanks,
Armando

Re: Automation Scripts and Repository View in OpenKM 6.2.2

PostPosted:Thu Feb 14, 2013 10:21 pm
by jllort
This is not necessary:
Code: Select all
if (eventType.equals("CREATE_DOCUMENT")) {
String userId = session.getUserID();
String path = eventNode.getPath();
To get user you should:
Code: Select all
String user = PrincipalUtils.getUser();
You have copyed older script for 5.x I suggest inspirate on it, but can not be used directly. Removing what I said and add the code to add user should be right.

Re: Automation Scripts and Repository View in OpenKM 6.2.2

PostPosted:Fri Feb 15, 2013 10:51 am
by armber
jllort,
thank you very much for your review and suggestion.

I have corrected the script to:
Code: Select all
import java.util.Map;
import com.openkm.api.OKMAuth;
import com.openkm.bean.Permission;

String path = eventNode.getPath();
OKMAuth oKMAuth = OKMAuth.getInstance();

// All Roles only will continue having read grants
Map hm = oKMAuth.getGrantedRoles(null, path);
for (String roleName : hm.keySet()) {
	oKMAuth.revokeRole(null, path, roleName, Permission.WRITE, false);
	oKMAuth.revokeRole(null, path, roleName, Permission.DELETE, false);
	oKMAuth.revokeRole(null, path, roleName, Permission.SECURITY, false);
}

// All users only will continue having read grants
hm = oKMAuth.getGrantedUsers(null, path);
for (String userName : hm.keySet()) {
	if (!session.getUserID().equals(userName)) {
		oKMAuth.revokeUser(null, path, userName, Permission.WRITE, false);
		oKMAuth.revokeUser(null, path, userName, Permission.DELETE, false);
		oKMAuth.revokeUser(null, path, userName, Permission.SECURITY, false);
	}
}
and I have inserted it in an Automation Rule for execution at a "doc_create" Event.

When it is executed, the following error that prevents the execution is found in the Tomcat log
Code: Select all
2013-02-15 10:54:30,268 [http-bio-0.0.0.0-8080-exec-15] ERROR com.openkm.automation.action.ExecuteScripting 
- Sourced file: inline evaluation of: ``import java.util.Map;  import com.openkm.api.OKMAuth;  import com.openkm.bean.Pe . . . '' :
Typed variable declaration : Attempt to resolve method: getPath() on undefined variable or class name: eventNode
Sourced file: inline evaluation of: ``import java.util.Map;  import com.openkm.api.OKMAuth;  import com.openkm.bean.Pe . . . '' : Typed variable declaration : Attempt to resolve method: getPath() on undefined variable or class name: eventNode : at Line: 5 : in file: inline evaluation of: ``import java.util.Map;  import com.openkm.api.OKMAuth;  import com.openkm.bean.Pe . . . '' : eventNode .getPath ( )
Should other classes be included in order that "eventNode" is recognized and returns the correct value?

Many thanks for your help,
Armando

Re: Automation Scripts and Repository View in OpenKM 6.2.2

PostPosted:Sat Feb 16, 2013 6:20 pm
by jllort
String path = eventNode.getPath(); now not exists you should use uuid directly is a variable injected transparent to the script and use OKMREpository.

Something like this ( I said using memory, could be totally correct, take a look on doxygen to see exact method name )
Code: Select all
String path = OKMRepository.getInstance().getPathByUUID(uuid);

Re: Automation Scripts and Repository View in OpenKM 6.2.2

PostPosted:Tue Feb 19, 2013 2:56 pm
by armber
jllort,
I followed your clues and I could make the script work.
Thank you for your help!
Armando

Re: Automation Scripts and Repository View in OpenKM 6.2.2

PostPosted:Thu Apr 11, 2013 1:00 pm
by armber
Hi,
I would like to implement a similar Automation Rule for execution at a "doc_move" Event.
Reading what has been reported for post "openkm6.2.2 automation file move java.lang.NullPointerExcept" ( http://forum.openkm.com/viewtopic.php?f=4&t=9293 ) it seems that this automation of "doc_move" Event has some problems to execute. Is this correct?

If it is possble, what should be the key structure of the automation script for "doc_move" Event that automatically changes rights to all users and roles that have rights on it when a Document is moved to a Folder?

Many thanks,
Armando

Re: Automation Scripts and Repository View in OpenKM 6.2.2

PostPosted:Fri Apr 12, 2013 7:16 pm
by jllort
I suggest open other post for it, otherside we will merge several questions on same topic and then difficult reading to other forum users.