Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to ristrict screen tab based on Group

Nagaraju Reddy March 24, 2021

Hi Team,

We are using JIRA DC, I am loking to hide a screen tab based on group.

 

Ex: I have View screen Tabs like 1,2,3,, when user in JSD group user can see all tabs in view screen. if user not in JSD group can see only 1,2 tabs.

 

I written code but I have not get it, can anyone help me on this.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript


@BaseScript FieldBehaviours fieldBehaviours

def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser


def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name


if ("jsd" in remoteUsersRoles) {
showTab(0);
showTab(1);
showTab(2);
}
else {
showTab(0);
showTab(1);
hideTab(2);
}

 

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 24, 2021

Hi Nagaraju,

For your requirement, you also need to invoke the GroupManager to verify if the user belongs to a particular group. 

You could try something like this:-

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def groupManager = ComponentAccessor.groupManager

hideTab(2)

if(groupManager.isUserInGroup(currentUser, "jira-servicedesk-users")) {
showTab(2)
}

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

 

Below is a print screen of the create screen for users in the jira-servicedesk-users group:-

image1.png

And below is a print screen of the create screen for users who are not in the jira-servicedesk-users group:-

image2.png

I hope this helps to answer your question :)

 

Kind Regards,

Ram

Nagaraju Reddy March 25, 2021

@Ram Kumar Aravindakshan _Adaptavist_ Thank you so much for your reply, yes this is working in only Create and edit screen only , but I need to hide this tab in view screen as well.

Can you see below screen shot, Tab2 hide in create screen but still I see in View ticket.

WhatsApp Image 2021-03-25 at 1.03.28 PM.jpeg

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 25, 2021

Hi @Nagaraju Reddy,

For your information, the Behaviour only works on the Create Issue, Update/Edit Issue, Assign Issue, and Workflow Transition screens and not on the View Issue Screen.

For more information on this, please visit the ScriptRunner documentation

Nagaraju Reddy March 25, 2021

Hi @Ram Kumar Aravindakshan _Adaptavist_ Thak your for your quick reply, thank you.

Suggest an answer

Log in or Sign up to answer