• Copy folder structure with permissions

  • 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.
 #42532  by xultz
 
Hi

I would like to automate a way to create a template with subfolders and permissions.
When I create a folder structure on the Templates section, and set the roles permissions to it, and copy it to the Taxonomy section, all the permissions get lost. Is it possible to copy the folders and keep the permissions to it?

If it is not possible, I would like to create a simple script to create that folder structure. I played with the scripting, and I was able to create the folders and subfolders using OKMFolder.getInstance().createSimple(), but I did not find the way to set the roles and permissions to the folder created. Is there a way to do it via scripting?

Thanks in advance for any help!
 #42537  by jllort
 
First of all, with OpenKM you can make anything. I suggest look in https://docs.openkm.com/apidoc/com/okm/6.3.2/ ( specially the classes under com.openkm.api ). For security focus in https://docs.openkm.com/apidoc/com/okm/ ... MAuth.html with the methods grantRole, grantUser, revokeRole, revokeUser and getGrantedRoles

I understand your point. Have some folder in templates and use them as an scheleton for new folders. We have been thinking on it, but unfortunatelly we have not find a way for distinguish between normal forlders and forder which represents hierarchical structure ( well really are ways for doing it, but we do not like much the ideas we got about how to solve it. When are not pleased with the way of solving something we prefer rest some time until finding a satisfactory way for doing it. You are welcome on proposing ideas about it ).
 #42540  by xultz
 
Thank you very much for your reply.

With your information and some examples I found in a blog, I could do the job. I will paste the code below because it can help someone else which, like me, is not a programmer and find it difficult to understand how the API works.

As a suggestion, when I create a folder structure (or like you named it, a skeleton), if I do it in the Templates section, I can copy it to the Taxonomy section. When I do it, it opens a popup windows, asking where to copy to. As far as I could understand (I didn't tested it), the folder skeleton will be set with the permissions of the root folder where I'm copying it. If it could be added in that popup window a checkbox labeled something like "Keep file/folder permissions", and with it checked it could preserve the permissions, it would be enough to do the job.


In my openkm I have three Roles defined, named "COMERCIAL", "ENGENHARIA" and "PRODUCAO". In the code below, it will create a folder named "Produto", and two subfolders for it, named "Teste1" and "Teste2". To the root folder (Produto) it will add the role "COMERCIAL" to it and give read permission. To the folder Teste1 it will add the "ENGENHARIA" role and give it read permission, and to the folder Teste2 it will add the PRODUCAO role and give it read and write permission.

Hope it helps!
Code: Select all
import com.openkm.api.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.module.db.stuff.*;

String pasta = "Produto";

String token = DbSessionManager.getInstance().getSystemToken();

String path1 = "/okm:root/" + pasta;
String path2 = path1 + "/Teste1";
String path3 = path1 + "/Teste2";

OKMFolder.getInstance().createSimple(null, path1);
OKMAuth.getInstance().grantRole(token, path1, "COMERCIAL", Permission.READ, false);

OKMFolder.getInstance().createSimple(null, path2);
OKMAuth.getInstance().grantRole(token, path2, "ENGENHARIA", Permission.READ, false);

OKMFolder.getInstance().createSimple(null, path3);
OKMAuth.getInstance().grantRole(token, path3, "PRODUCAO", Permission.READ + Permission.WRITE, false);
 #42555  by jllort
 
The script you propose create a new folder with security grants. As an alternative could be used some action ( java class or script ) linked with copy action ( is more complex, but probably near all you wish you can take a look here https://wiki.openkm.com/index.php/Automation )
 #42562  by xultz
 
Thank you for your tip!

In fact, I though about creating an automation, where when I create a folder inside an special folder, it would trigger the automation and create all the subfolders with the permissions.
The problem is that I could not enable automation in my installation, I tried to follow that link: https://wiki.openkm.com/index.php/Enable_automation
but it didn't work. It would be great if the text give some more detailed information about how to do it, I copied and pasted all the "INSERT INTO..." commands to the database query field (of the administration section) and pressed the "Execute" button. Nothing happened, and in the Automation section, the action and validation list stays empty.

Do you have any idea how can I enable it?

Thank you for any help!
 #42589  by jllort
 
Upload into zip file here ( you can insert attachments in the post, see below the text area )

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.