Hi,
Via a Scriptrunner Fragment I want to have the option More -> Labels in issues of 4 Jira projects only available for users in the project roles 'Administrators', 'Scrum Masters', 'Productowners'.
With the following script I am able to make the option More -> Labels in issues available only to users in the project roles 'Administrators', 'Scrum Masters', 'Productowners', but this now applies to all jira projects.
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 allowedRoles = ['Administrators', 'Scrum Masters', 'Productowners','Viewers','Service Desk Team']
def isUserInAllowedRoles = allowedRoles.any{ projectRole ->
def role = projectRoleManager.getProjectRole(projectRole)
projectRoleManager.isUserInProjectRole(currentUser, role, currentProject)
}
return ( isUserInAllowedRoles || !jiraHelper.project?.key in ["SH3","SF3","SI3","SM3"])
System does not respond (properly) to
return ( isUserInAllowedRoles || !jiraHelper.project?.key in ["SH3","SF3","SI3","SM3"])
How do I modify the script so that it only applies to the 4 jira projects?
Thank you in advance.
Regards, Marco Brundel
This is a follow up question to
WIthout actually having tested anything, why don't you just leverage the "currentProject" object you're already getting via the ProjectActionSupport (I've never used that).
I would do this first so you don't bother checking permissions if the project isn't correct.
You could do it like this (a bit of future-proofing if you have other projects/role combinations later)
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 controlledProjectMaps = [
[
projects: ["SH3", "SF3", "SI3", "SM3"],
roles : ['Administrators', 'Scrum Masters', 'Productowners', 'Viewers', 'Service Desk Team']
]
]
if (!controlledProjectMaps.any { it.projects.contains(currentProject.key) }) {
//keep current functionality for non-controlled projects
return true
}
def projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager)
def allowedRoles = controlledProjectMaps.find{it.projects.contains(currentProject.key)}.roles
def isUserInAllowedRoles = allowedRoles.any { projectRole ->
def role = projectRoleManager.getProjectRole(projectRole)
projectRoleManager.isUserInProjectRole(currentUser, role, currentProject)
}
return isUserInAllowedRoles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.