• Automation Scripts and Repository View in OpenKM 6.2.2

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #21330  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
 #21351  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)
 #21358  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
 #21376  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.
 #21389  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
 #21428  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);
 #22453  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

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.