Setting user permissions programmatically

LabKey Support Forum (Inactive)
Setting user permissions programmatically sadcat  2012-09-07 18:15
Status: Closed
 
Hi,

is it possible to set user's permissions programmatically?

Thanks,
X
 
 
Matthew Bellew responded:  2012-09-08 11:23
https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.Security.html

These are the same APIs used by the built-in administration pages. Of course you have to be logged in as an administrator to change permissions.

These _should_ work for datasets and other "securable resources" , but they aren't used by those management pages, so your mileage may vary. Let us know if you hit any snags.
 
sadcat responded:  2012-09-08 11:47
Hi, Matthew,

thanks for responding. Essentially, what I am seeking to accomplish is to programmatically create a few user groups/users with certain roles. So far, the way I managed it through interface, is to create users, and then set their role in the "Roles" interface (I am attaching a picture). I looked over the LABKEY.Security documentation, and I see one can retrieve the roles, but not set them. Am I missing something?
Is it possible to write a script to create groups/users with certain permissions/roles ("Author", "Administrator") etc.?

Thanks!
 
Matthew Bellew responded:  2012-09-08 13:53
Sorry, I should have given a little more direction. Not enough coffee...

The way you add permissions is not by editing users, but b y editing security policies. You get the policy for the current container using

LABKEY.Security.getPolicy(config)

see https://www.labkey.org/download/clientapi_docs/javascript-
api/symbols/LABKEY.SecurityPolicy.html

Then you can grant or remove roles to users/groups .

   addRoleAssignment(principalId, role)
   clearRoleAssignments(principalId)

then use

LABKEY.Security.savePolicy(config)
 
sadcat responded:  2012-09-08 16:39
Oh! Got it! Thanks,

Xenia