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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

 

 

1 answer

1 accepted

0 votes
Answer accepted

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Jira Cloud Performance Improvements

Hello everyone, I am a product manager in the Jira Cloud team focused on making sure our customers have a delightful experience using our products. Towards that goal, one of the areas which is extr...

171 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you