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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,318
Community Members
 
Community Events
184
Community Groups

Hide a UI element in one project depending on Role

Hi All,

I am using the "Hide system or plugin UI element" from ScriptRunner Add-On to hide a Link in the UI and it works to hide it for all members of the project.

I have also found a script to hide to all the members except the project admin. I am able to perform the above for all project, but my condition is to restrict only one project. 

Can anyone suggest How to restrict on one project based on project role.

Below is the script I found out and using 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

def project = jiraHelper.project?.key


String roleName = "Administrators"

if (project != null) {

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ProjectRoleManager projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager);
def projectRole = projectRoleManager.getProjectRole(roleName)

return projectRoleManager.isUserInProjectRole(user, projectRole, issue.getProjectObject())

}

return false

 

 

2 answers

1 accepted

0 votes
Answer accepted
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.
May 25, 2020

Which UI link you you hiding? That would help.

I see that you are using issue.getProjectObject() as well as jiraHelpder.project.key.
I'd say if this UI link you want to hide is related to issues, you only need to use the issue.

But the following should work:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

String roleName = "Administrators"
def projectKeysToRestrict = ['ABC', 'CDE']
if (issue?.projectObject?.key in projectKeysToRestrict ) {
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def projectRole = projectRoleManager.getProjectRole(roleName)
//hide for restricted project unless user is in role
return projectRoleManager.isUserInProjectRole(user, projectRole, issue.projectObject)

} else {
return true //show for all other project
}

Hi Peter,

 

I was trying to hide the clone from the more option. I have checked the above code and it's working fine.

 

Thanks for the help.

 

Vasanta.

Hi @Peter-Dave Sheehan

This script was working, I want to restrict clone option to specified issuetypes in a project who dont have project admin access. How can we add issuetypes in above code?

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.
May 30, 2022

issue?.issueType?.name in ['issueType1', 'issueType2', 'etc']

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

String roleName = "Administrators"
def projectKeysToRestrict = ['ABC', 'CDE']
def issueTypesToRestrict = ['issueType1', 'issueType2']
if (issue?.projectObject?.key in projectKeysToRestrict && issue?.issueType?.name in issueTypesToRestrict ) {
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def projectRole = projectRoleManager.getProjectRole(roleName)
//hide for restricted project unless user is in role
return projectRoleManager.isUserInProjectRole(user, projectRole, issue.projectObject)

} else {
return true //show for all other project
}

Thanks!!

This worked...

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events