How to get groups, which are assigned to a specific role in a project?

I want to get the names of groups, which are assigned to a role in a project, but only found a way to get all usernames that are assigned to a role, with the following:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.security.PermissionManager;
import com.atlassian.jira.security.roles.ProjectRole;
import com.atlassian.jira.security.roles.ProjectRoleActors;
import com.atlassian.jira.security.roles.ProjectRoleManager;
import com.atlassian.jira.user.ApplicationUser;


Collection<Project> projects = permissionManager.getProjects(new ProjectPermissionKey("BROWSE_PROJECTS"), appUser);
ProjectRoleManager projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager.class);
ProjectRole projectRole = projectRoleManager.getProjectRole("Role Name");

for(Project project : projects){
ProjectRoleActors projectRoleActors = projectRoleManager.getProjectRoleActors(projectRole, project);
System.out.println(projectRoleActors.getUsers().toString());
}

 Is there any way to get the groupnames instead of all usernames?

1 answer

0 votes
Micky Caritte Community Champion Jan 22, 2018

Hi,

You might want to use the ProjectRoleManager.getProjectIdsContainingRoleActorByNameAndType() method, you can define which type of actor you want to get, in your case it would be ProjectRoleActor.GROUP_ROLE_ACTOR_TYPE.

More details here: https://docs.atlassian.com/software/jira/docs/api/7.0.2/com/atlassian/jira/security/roles/ProjectRoleManager.html#getProjectIdsContainingRoleActorByNameAndType-java.lang.String-java.lang.String-

Hope this helps!

Cheers

Micky Caritte Community Champion Jan 22, 2018

This is based on knowing the group name. If you don't want to check all groups individually, you might want to search for an alternative solution. Will keep you posted if I can find one!

Cheers

Hi,

thanks for this, but you already say it. It would be more comfortable if I get the groupnames directly by the project, instead of run through all groupnames individually and compare each projectId with the result list of the function.

Would be great if there is any solution! Otherwise I go on with this one...

Micky Caritte Community Champion Jan 23, 2018

Sure! Please keep us posted if you find any better solution, very interesting question :)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Thursday in Jira

Continuous visibility with the new Jira Software Cloud and Bitbucket Cloud integration

Hey Atlassian community, I am a PM on the Bitbucket Cloud team and I am excited to share that we just released an improvement to the Jira Software and Bitbucket Cloud integration. With the newly im...

69 views 0 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you