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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to find all projects where a group has a role?

There is a standard way to check using a group in all permission schemes. But is there a way to check using a group in all projects' roles?

4 answers

1 accepted

9 votes
Answer accepted

Try this Groovy script using script console

import com.atlassian.jira.bc.projectroles.ProjectRoleService;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
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.security.roles.RoleActor;

StringBuilder output = new StringBuilder();
ProjectManager projectManager = ComponentAccessor.getProjectManager();
ProjectRoleService projectRoleService = (ProjectRoleService) ComponentAccessor.getComponentOfType(ProjectRoleService.class);
ProjectRoleManager projectRoleManager = (ProjectRoleManager) ComponentAccessor.getComponentOfType(ProjectRoleManager.class);

final Collection<ProjectRole> projectRoles = projectRoleManager.getProjectRoles();
for(Project project : projectManager.getProjectObjects())
{
    for(ProjectRole projectRole: projectRoles)
    {
        final ProjectRoleActors projectRoleActors = projectRoleManager.getProjectRoleActors(projectRole, project);
        for (RoleActor actor : projectRoleActors.getRoleActors()) {
            if(actor.getDescriptor().equals("TheGroupNameYouLookingFor")){
                output.append(project.getKey()).append(" : ").append(projectRole.getName()).append(" : ").append(actor.getDescriptor()).append("\n");
            }
        }
    }
}
return output.toString();

Hi Renjith,

Thank you very much!

I hope this ready feature will be added to the next JIRA version.

BR,

Ivan

Hi Renjith,

Can you guide me a solution to get projectId in "projectroleactor" table ?

if I debug to method bellow then I can see projectId but I can't get projectId.
for (RoleActor actor : projectRoleActors.getRoleActors()) {

    // something

}1.png2.png

Thanks.

A workaround would be to find a user that is part of that role, go to the View Project Roles and then Edit Project Roles for User and it will show if a group is mapping that user to a project role and will name the group.

@Kalen Brown This workaround helped me. Thanks!

Hi Ivan,

Currently, it is not possible to check a group has specific project roles in all projects. You can raise a new feature request for this at https://jira.atlassian.com and vote for it. In order to be implemented, it must meet certain levels according to our Implementation of new features policy.

Best Regards,

Steven

Hi Steven,

Thank you, I will.

BR,

Ivan

Hi @Renjith Pillai ,

Getting error as below (also in screenshot), while running in Scriptrunner Console

startup failed: Script991.groovy: 15: unexpected token: Collection @ line 15, column 7. final Collection<ProjectRole> projectRoles = projectRoleManager.getProjectRoles(); ^ 1 error
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script991.groovy: 15: unexpected token: Collection @ line 15, column 7. final Collection<ProjectRole> projectRoles = projectRoleManager.getProjectRoles(); ^ 1 error 

 Any thoughts ?Err1.png

@Lokesh 

Change de line as the image belowChange.PNG

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you