I am trying to find a way to programmingly create/modify a permissionshchme ( Backgroud: users want different projects has different dedicated permission scheme, they provided a excel file with all the permissions they want. It's very time consuming to add different groups/roles to different permissions one by one, and we need to do it on multiple staging/production servers ). Our JIRA version is 6.4.
So far, I am forcus on
https://docs.atlassian.com/jira/latest/com/atlassian/jira/permission/PermissionSchemeManager.html
The problem is it have getPermissionSchemeEntries, there is no setPermissionSchemeEntries or createPermissionSchemeEntries.
It has a createSchemeEntity , but didn't provide much detail how I can use it.
It has a "getEntities(org.ofbiz.core.entity.GenericValue scheme, ProjectPermissionKey permissionKey, String type, String parameter)", although Deprecated, but it still work and helped me to understand how the permissions are saved as a object and in database.
It return existing permissions like:
Id:[GenericEntity:SchemePermissions][scheme,13802][parameter,10900][permissionKey,VIEW_DEV_TOOLS][permission,null][id,28242][type,projectrole]
Now I think I can create/clone a GenericEntity:SchemePermissions object and submit it to createSchemeEntity , but the question is how I can feed it a correct id.
I found the data in database schemepermissions table:
id | scheme | permission | perm_type | perm_parameter | permission_key
-------+--------+------------+-------------+----------------+------------------------
28242 | 13802 | | projectrole | 10900 | VIEW_DEV_TOOLS
So the id has to be unique, and it's not a auto increased sequence. Even if I get a max_current_id+1 from database, I am not sure it's safe to use it. Directly insert records into schemepermissions table might be another option, but it's probably even more dangerous.
Community moderators have prevented the ability to post new answers.
Hi Jack,
I would suggest that you create all the permission schemes manually on the test server and then use Configuration Manager for JIRA to move these schemes between the dev/test/staging/production instances you have, so you don't need to do this manually.
If you sill want to do this via script runner here's a sample pseudo code required to modify permission scheme entities
Long permissionSchemeId = scheme.id String permissionValue = // roleId, username, groupname, custom field id String type = //the permission type - group or user or group/user custom field String permissionKey = //the id of the permission SchemeEntity schemeEntity = new SchemeEntity(type, permissionValue, permissionKey); GenericValue schemeGV = permissionSchemeManager.getScheme(permissionSchemeId); permissionSchemeManager.createSchemeEntity(schemeGV, schemeEntity);
WOW, just WOW
Thanks So much Boris, yes I am aware project configurator, it will help but only solve half of the problem and it's not free.
I was actually just stuck on
SchemeEntity schemeEntity =
new
SchemeEntity(type, permissionValue, permissionKey);
The document says :
//SchemeEntity(String type, String parameter, Object entityTypeId)
But I didn't find what is entityTypeId. Should have just tried it.
Now I tried
perm="WORK_ON_ISSUES" roleid="10002" p=com.atlassian.jira.permission.ProjectPermissions."${perm}" //SchemeEntity(String type, String parameter, Object entityTypeId) String permissionValue = roleid String type = "projectrole" String permissionKey = //the id of the permission SchemeEntity schemeEntity = new SchemeEntity(type, permissionValue, permissionKey); psManager.createSchemeEntity(s1, schemeEntity as SchemeEntity )
And it worked!
You are amazing!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.