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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Scriptrunner Fragment the option More -> Labels in issues of 4 Jira projects only for certain users

Edited
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.
Feb 10, 2022

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 

https://community.atlassian.com/t5/Adaptavist-questions/How-can-a-Scriptrunner-Fragment-make-it-apply-to-multiple/qaq-p/1932960

Screenshot 2022-02-10 at 14.28.27.png

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Feb 10, 2022

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
TAGS
AUG Leaders

Atlassian Community Events