List Project Role membership

Found an old script to do this that needed refreshing. In so doing, I discovered the “ProjectRolePicker” dynamic form field type does not work on my test instance that has an expired license, although the ProjectPicker does. I updated it to the correct developer license and it works as expected.

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.onresolve.scriptrunner.parameters.annotation.ProjectRolePicker
import com.onresolve.scriptrunner.parameters.annotation.ProjectPicker
import org.apache.log4j.Level
 
log.setLevel(Level.DEBUG)
@ProjectPicker(
    label = 'Project', description='Multi project picker', placeholder = 'Pick project(s) or leave empty for all', 
    includeArchived = false,
    multiple=true
)
List<Project> projectList
@ProjectRolePicker(label = 'Project role', description = 'Project role picker')
ProjectRole projectRole
def projectManager = ComponentAccessor.getProjectManager()
def projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager.class) as ProjectRoleManager
def roleMap = [:]
def defaultRole = "Administrators"

if (projectRole == null) {
    log.warn("No role selected, using default of $defaultRole")
    projectRole = projectRoleManager.getProjectRole(defaultRole)
}
if (projectList.isEmpty())
    projectList = projectManager.getProjectObjects()

projectList.each { Project project ->
    ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(projectRole, project)
    log.debug "Key: $project.key, Count: ${actors.getUsers().size()} Users: ${actors.getUsers()*.name}\n"
    if (actors.getUsers().size() > 0) {
        roleMap.put(project.key, actors.getUsers()*.name)
     }
}
return roleMap
2 Likes