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

rahuldanwade
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.
September 26, 2016

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

1 vote
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 5, 2016

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

0 votes
rahuldanwade
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.
September 28, 2016

@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 Sign up to answer