Restricting issue creation of certain Issue Types based on user project role

surender kallam January 9, 2018

Hi Team,

I just want to know, if there is a way to restrict creation of an issue type based on the Project Role.

For example,

I have 3 roles in my project,

  • Project Role Admin
  • Project Role Developer
  • Project Role User

And i have the below issue types,

  • Story
  • Epic
  • Bug
  • Task

I want only Project Role Developers to be able to create only Bug issue type.

Please let me know incase of more information required.

Thank You,
Surender

4 answers

1 accepted

1 vote
Answer accepted
Aidan Derossett _Adaptavist_
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.
January 10, 2018

Hey Surender!

Thanks for raising this question! :D

To clarify, are you saying that you want to limit the options for Developers so that they can ONLY select the "Bug" issue type?

After doing some digging, I'm afraid I've come back with some info that's more disconcerting than I would have hoped. As it turns out, the Issue Type field is one of the only fields that, using a Behaviour, you can't manipulate the selectable options for. This has been a long-standing issue and is recorded in SRJIRA-1010.

Although that throws out the cleanest solution, you could still implement essentially the same functionality with a ScriptRunner Behaviour. For instance, you can still set the Issue Type field. So you could use a Behaviour to check if the user is a Developer and then automatically set the field to "Bug" and lock it so that they cannot change the Issue Type. The code to do this would look something like:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE

// if the current user is in the Developer role only, set the issue type to "Bug", and lock it
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def user = ComponentAccessor.jiraAuthenticationContext.user

def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
log.warn("Thing: "+remoteUsersRoles)
//Set "Project Role Developer" to the name of the project role that you'd like to check for
if (remoteUsersRoles == ["Project Role Developer"]) {
def constantsManager = ComponentAccessor.getConstantsManager()
def bugIssueType = constantsManager.getAllIssueTypeObjects().find{
it.name == ["Bug"] }
//Set the issue type to Bug and make it read-only
getFieldById(ISSUE_TYPE).with{
setFormValue(bugIssueType.id)
setReadOnly(true)
}
}

There is also an example of setting the Issue Type in our documentation here.

Let me know if this solution would work for you or if we need to explore some other avenue. Also, if you need help implementing the above Behavior, give me a holler. :D

Best,

Aidan

Eric Collins May 17, 2018

@Aidan Derossett _Adaptavist_I am trying to allow almost the opposite. If a user is a developer they can create issuetypes Task or Bug but not Epic. Any advice?

Aidan Derossett _Adaptavist_
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.
May 29, 2018

 

Hey Eric!

Sorry it took me so long to get back to you :(

If you want to restrict a particular role to two different issue-types, you may run into some trouble with the bug that I mentioned in the above comment. Unfortunately, as of right now you can't restrict the options that are available in the issue-type select list. So you'll have to implement some other method to get this same functionality.

For instance, you could write some custom JavaScript to do it for you and then inject it into JIRA using a ScriptRunner Web Resource. That's not the most trivial of tasks, but it would be the cleanest workaround. :)

Best,

Aidan

2 votes
Anand Vardhan August 27, 2019

Is there any way to restrict on JIRA cloud. I'm using properties in the workflow to restrict his. Below is what I'm adding on JIRA creation:

jira.permission.create=denied.

 

Is this correct or is there any way around it.

0 votes
Jeevan Kumar M J May 15, 2018

@Peter DeWitt and @Aidan Derossett _Adaptavist_, Even i am also raising the same query where I need to restrict a group or individual users for certain issue types.

I saw the above script and i can add them into scriptrunner, but I have a question here. Where can i call this script? How will this script help in restricting the group?

It would be greatest help if I get your guidance here.

thank you in advance

0 votes
Peter DeWitt
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 9, 2018

@surender kallam, If you are using different workflows for each issuetype, you can use a validator on the issue creation link.  Jira suite utilities will allow you to validate against project roles.  Naked Jira may require specific user groups to be used.

 

.pd

Abhishek Srivastava November 2, 2018

Which validator should i choose , tehre are many options for validators

Suggest an answer

Log in or Sign up to answer