Groovy/ Behaviours script to hide/blur certain issuetypes from certain users, groups or project roles

Hi All 

Warm Greetings!!

Is it possible to hide selected issue types from users unless they are in a specific group? We have a number of issue types that are for internal use only but users often mistakenly use them. We'd like to hide them from everyone but those in our team's group?

Eg:-

Project contains 3 issue types

Task

Bug

New Feature

 

Bug issue type should only be created by users in JIRA-Test group.

 

I tried simple script validator like

issue.projectObject.key == 'ABCD' && isUserMemberOfRole('Administrators') && issue.issueTypeObject.name == 'Bug'

but it won't be nice to tell the users that they are not allowed to create issue type after filling entire form.

I remember that @Jamie Echlin [Adaptavist] wrote the similar script to implement this but that script isn't there in https://scriptrunner.adaptavist.com or maybe I'm not looking at the correct page.

 

please suggest

 

2 answers

Hi Rahul,

I have looked into this issue for you and unfortunately it is not possible to restrict the list of issue types using the Behaviours module of ScriptRunner out of the box. The closest you can do is to set just one issue type based on a users role or group as described in the documentation here.

However I have created a workaround for you which I have tested on my local JIRA 7.1.0 instance running ScriptRunner version 4.3.5.

The way the workaround works is by creating a new custom field of the Single Select List type called Issue Type Selection and adding the issue types that users not in the group can select.

You would then add a behaviour onto the new select field which makes the Issue Type field read only and the new select field mandatory if the user is not in the group and sets the issue type to the value of the Select List Field. Also if the user is a team member then it allows them to use the default Issue Type field and hides the new select field.

I have attached the script and config that is needed for this below. Note - I have used the jira-software-users group as my example admin group but you will need to replace this with the name of the group inside your instance.

Code:

 

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE

def issueType = getFieldById(ISSUE_TYPE)
def issueTypeSelect = getFieldByName("Issue Type Selection")

// Get the issueTypeSelect Value as a String
def issueTypeSelectVal = issueTypeSelect.getValue().toString()

// Get a pointer to the current logged in user
def userUtil = ComponentAccessor.getUserUtil()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// If user is not in admin group then make the field read only
if (!userUtil.getGroupNamesForUser(currentUser.name).contains("jira-software-users")) {
    issueType.setReadOnly(true)
    issueTypeSelect.setRequired(true)

    // Set the Issue Type to the Select List Value
    issueType.setFormValue(issueTypeSelectVal)

// If the user is and admin then they may use the standard Issue Type field
} else if (userUtil.getGroupNamesForUser(currentUser.name).contains("jira-software-users")) {
    issueType.setReadOnly(false)
    issueTypeSelect.setRequired(false)

    //Also Hide the Field as the admin does not need it
    issueTypeSelect.setHidden(true)

}

 

Config:

Screen Shot 2016-10-05 at 16.44.26.png

I hope this helps.

Thanks

Kristian

@Jamie Echlin [Adaptavist]

 

Could you point me to the script or give some insights on this.

thanks in advance.

 

 

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Feb 15, 2018 in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

1,230 views 6 19
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot