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,560,515
Community Members
 
Community Events
185
Community Groups

Hide a UI element depending on Role

Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 15, 2018

Hi community,

 

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.

Is it possible to change the condition so that the link is only hidden for the members of some project roles? I have not found any way to access the roles or the current user yet.

 

Thanks

Bastian

4 answers

1 accepted

0 votes
Answer accepted
Alexey Matveev
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.
Apr 15, 2018

It would be like this

 

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
Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 16, 2018

Hi @Alexey Matveev,

thank you very much for this quick response.

I had to change the line:

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

to 

return projectRoleManager.isUserInProjectRole(user, projectRole, jiraHelper.project)

 because there is not always an issue selected, but now it works great.

 

Best regards

Bastian

Like kumar jira likes this

Hi @Alexey Matveev ,

Could you please tell how to modify your suggested code to have some operations visible for two or three different project roles instead of just "Administrators"? Like visible for project roles "Administartors" and "Service Desk Team".

Many thanks! :)

Hi @Bojana Vasic 

Try this solution for more than one role:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.util.UserManager

def project = jiraHelper.project?.key

if (project != null) {

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

def projectRoleAdmin = projectRoleManager.getProjectRole("Administrators")
def projectRoleSDT = projectRoleManager.getProjectRole("Service Desk Team")

Boolean isAdmin = projectRoleManager.isUserInProjectRole(user, projectRoleAdmin, jiraHelper.project);
Boolean isSDT = projectRoleManager.isUserInProjectRole(user, projectRoleSDT, jiraHelper.project);

if(isAdmin || isSDT){
return true;
}

}

return false

Best regards,

Artiom

Is it possible to Hide UI element for a particular status?

Hi all,

Could you help me please to hide voters from mentioned project in Jira ?

I have tried to hide voters with same code, but it isn't working.

Maybe I am using not correct module ?

I tried this modules

com.atlassian.jira.plugin.system.issueoprations:vote-issue,

com.atlassian.jira.plugin.system.issueoprations:view-voters,

com.atlassian.jira.plugin.system.issueoprations:unvote-issue

Suggest an answer

Log in or Sign up to answer