How can a Scriptrunner Fragment make it apply to multiple project roles?

Marco Brundel
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.
February 3, 2022

Hello,

How can a Scriptrunner Fragment make it apply to multiple project roles?

I'm now using 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.action.ProjectActionSupport
import com.atlassian.jira.project.Project
import com.atlassian.jira.security.roles.ProjectRoleManager
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()


ProjectActionSupport projectSupport = new ProjectActionSupport();
Project currentProject = ComponentAccessor.getProjectManager().getProjectObj(projectSupport.getSelectedProjectId());

def projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager)
def role = projectRoleManager.getProjectRole("Administrators")
return ( projectRoleManager.isUserInProjectRole(currentUser, role, currentProject) || jiraHelper.project?.key != "SH3")



but want script to also apply to Scrum Masters and Approvers project roles and not only to Administrators.

So what should I include instead of

def role = projectRoleManager.getProjectRole("Administrators")

Thank you very much for your response.

Greetings Marco

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Peter-Dave Sheehan
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.
February 3, 2022

You can try something like this:

def projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager)

def allowedRoles = ['Administrators', 'Scrum Masters']
def isUserInAllowedRoles = allowedRoles.any{ projectRole ->
def role = projectRoleManager.getProjectRole(projectRole)
projectRoleManager.isUserInProjectRole(currentUser, role, currentProject)
}
return ( isUserInAllowedRoles || jiraHelper.project?.key != "SH3")
Marco Brundel
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.
February 6, 2022

Hi @Peter-Dave Sheehan ,

Thank you, this script works in my scriptrunner fragment.

Regards, Marco

TAGS
AUG Leaders

Atlassian Community Events