Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Set insight role permission on objecttypes with java

Reto
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 6, 2021

Hi,

I'd like to automatize the configuration of permissions of Insight Objecttype with java or REST api. Is that supported and has anyone an idea how I can do that?

Many thanks! 

2 answers

1 accepted

1 vote
Answer accepted
Puya Alemirad
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 10, 2021

Hi,

You can use the JAVA API for this. You can use:

class ConfigureFacadeImpl
public void storeActorsForRoleBean(Map<String,Set<String>> newRoleActorBeans,
int roleBeanId)

Parameter newRoleActorBeans is a map where the key is a String either “atlassian-group-role-actor” or “atlassian-user-role-actor” depending on if it’s a group or a user and the value Set<String> is either a Set of userKeys or groupName.

Parameter roleBeanId is the specific id for the role, for example the id for developer role for "Your object schema" or  manager for object type "Your object type". All these roles has their own id. 

To get the roleBeanId for the specific role you are configuring you can use either of the following methods (depending on if the role is in the objectSchema and objectType):
public List<com.riadalabs.jira.plugins.insight.services.model.RoleBean>findRoleBeansByObjectType(int objectTypeId)
 
public List<com.riadalabs.jira.plugins.insight.services.model.RoleBean>findRoleBeansByObjectSchema(int objectSchemaId)

 The method will return a list of RoleBeans, one for each role (example manager, developer and user). The RoleBean will also include the id. 

Note: When storing a new user or group to a role you'll have to include all the ones that should be in the role because storeActorsForRoleBean will replace the users and groups in a specific role and not just add new ones to it. If you don't know who or which group already was included in the role and you just want to add one then you can use the info from the RoleBean when picking up the id. The RoleBean has a variable called roleActorBeans which is a List of 
com.riadalabs.jira.plugins.insight.services.model.RoleActorBean;
for each user/group. The RoleActorBean includes variable "type" which is either “atlassian-group-role-actor” or “atlassian-user-role-actor”  and param "typeParam" which is either userKey or groupName. 

Example 1:
You have "user1" as manager for a schema or object type and would like to add "user2" as manager as well. Your Map newRoleActorBeans should then contain both "user1" and "user2" in the set of strings for the key “atlassian-user-role-actor", and the second param should be the id for manager for the specific object type or schema. 

Example 2: You have "user1" as manager for a schema or object type and would like to add group "jira-group" as manager as well. Your Map newRoleActorBeans should then contain two entries where one contains a key "atlassian-user-role-actor" and the other entire with key “atlassian-group-role-actor” and the set of strings with the key for "jira-group". 

Hope this works for you and good luck!

Cheers // Puya
Puya Alemirad
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 10, 2021
Reto
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 10, 2021

Hey Puya, thank you very much for the extremely detailed answer!

1 vote
Mo Ziauddin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 1, 2022

I have the following code that finds a objectType I want and add a group to each role for that objecttype. If it helps someone then thats great.

 

import com.atlassian.jira.component.ComponentAccessor
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ConfigureFacade
import com.riadalabs.jira.plugins.insight.services.model.RoleBean
import com.riadalabs.jira.plugins.insight.services.model.MutableObjectTypeBean
import com.riadalabs.jira.plugins.insight.services.model.ObjectTypeBean

def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectFacade)
def objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeFacade)
def configureFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ConfigureFacade
String mnemonic = 'TEST'
Integer schemaId = 5
List parentTypeNames = ['OT1, 'OT2', 'OT3']
String userName = 'myusername'
String groupName = 'jira-users'
String userRoleType = "atlassian-user-role-actor"
String groupRoleType = "atlassian-group-role-actor"

// create sets

Set<String> groupActors = new HashSet<String>()
groupActors.add(groupName)

// get mutable one of the object beans
MutableObjectTypeBean objTypeBean = objectTypeFacade.findObjectTypeBeans(schemaId).find {
it.name == parentTypeNames[1]
}.createMutable()
log.warn(objTypeBean.id)

// find all roles
List<RoleBean> roles = configureFacade.findRoleBeansByObjectType(objTypeBean.id)
roles.each {
// store the actors to role bean
configureFacade.storeActorsForRoleBean([(groupRoleType): groupActors] as java.util.Map, it?.id)
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events