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?
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.
Hope this helps!
Cheers
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure! Please keep us posted if you find any better solution, very interesting question :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Finn Bökenkamp ,
Here is the working solution to get the groups assigned to a particular project role in a project.
Set<String> projGroupNames =new HashSet<String>();
ProjectRoleManager projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager.class);
ProjectRole projectRole = projectRoleManager.getProjectRole("Administrators");
ProjectRoleActors projectRoleActors = projectRoleManager.getProjectRoleActors(projectRole, project);
for(RoleActor actor : projectRoleActors.getRoleActorsByType(ProjectRoleActor.GROUP_ROLE_ACTOR_TYPE)) {
projGroupNames.add(actor.getParameter());
}
Hope this helps.
Thanks,
Santwana
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.
Hi @Ankush Kumar ~ I have already provided the above. Hope that helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Santwana Sarangi {Appfire} getting error "unable to resolve class RoleActor"
for(RoleActor actor : projectRoleActors.getRoleActorsByType(ProjectRoleActor.GROUP_ROLE_ACTOR_TYPE)) {
projGroupNames.add(actor.getParameter());
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.