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

Ivan Donigevich November 8, 2013

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
Renjith Pillai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

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();

Ivan Donigevich November 13, 2013

Hi Renjith,

Thank you very much!

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

BR,

Ivan

h h November 24, 2020

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.

1 vote
Kalen Brown June 14, 2018

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.

Ilakiya Srinivasan May 18, 2020

@Kalen Brown This workaround helped me. Thanks!

0 votes
Lokesh March 7, 2019

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

Claudio Maia April 3, 2019

@Lokesh 

Change de line as the image belowChange.PNG

0 votes
StevenA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2013

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

Ivan Donigevich November 10, 2013

Hi Steven,

Thank you, I will.

BR,

Ivan

Suggest an answer

Log in or Sign up to answer