Page 1 of 1

Copy folder structure with permissions

PostPosted:Fri Nov 04, 2016 6:09 pm
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!

Re: Copy folder structure with permissions

PostPosted:Sat Nov 05, 2016 9:22 am
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 ).

Re: Copy folder structure with permissions

PostPosted:Mon Nov 07, 2016 3:51 pm
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);

Re: Copy folder structure with permissions

PostPosted:Thu Nov 10, 2016 7:47 am
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 )

Re: Copy folder structure with permissions

PostPosted:Thu Nov 10, 2016 11:04 am
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!

Re: Copy folder structure with permissions

PostPosted:Sun Nov 13, 2016 7:02 pm
by jllort
Share with us the class and the SQL insert and we will take a look on it.

Re: Copy folder structure with permissions

PostPosted:Mon Nov 14, 2016 10:35 am
by xultz
Hello!

Sorry if it is a dumb question, but how do I do it?

Re: Copy folder structure with permissions

PostPosted:Wed Nov 16, 2016 6:04 pm
by jllort
Upload into zip file here ( you can insert attachments in the post, see below the text area )