Forums

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

Limit issue creation by project role

Nils Althaus October 24, 2024

We want to limit the creation of all issue types except for one. We have a separate workflow for the issue type that the users are allowed to create.

I tried solving this with a custom script validator (ScriptRunner) on the creation transition, which I based off of an example script:

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.security.roles.ProjectRoleManager

// the name of the project role

def roleName = '_project_admin'

def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

def role = projectRoleManager.getProjectRole(roleName)

projectRoleManager.isUserInProjectRole(issue.reporter, role, issue.projectObject)
Unfortunately, this doesn't work right. When I try to create an issue with this workflow with a test user that doesn't have the role the issue is still created. I don't know anything about GroovyScript - what is going wrong here?

2 answers

1 accepted

2 votes
Answer accepted
Samuel Gatica _ServiceRocket_
Community Champion
October 24, 2024

Hi @Nils Althaus 

Try the following:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
 
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
 
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
 
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def issueTypeField = getFieldById(ISSUE_TYPE)
 
def userRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
def availableIssueTypes = []
 
if ("Users" in userRoles) {
    availableIssueTypes.addAll(["Query", "General Request"])
}
 
if ("Developers" in userRoles) {
    availableIssueTypes.addAll(["Bug", "Task", "New Feature"])
}
 
issueTypeField.setFieldOptions(availableIssueTypes)

 

As detailed in Doc Restricting Available Issue Types 

 

Best regards

Sam

Nils Althaus October 25, 2024

Hi @Samuel Gatica _ServiceRocket_,

this is the perfect solution for us. Thank you.

 

Best regards

Nils

2 votes
Manoj Gangwar
Community Champion
October 24, 2024

Hi @Nils Althaus Welcome to the community!

You may use the Permission Validator on issue creation and select the project role to restrict issue creation.

Nils Althaus October 24, 2024

I actually didn't think of that. In our specific case, this will work since the users who are not allowed to create the other issue types are in a different role with fewer permissions.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events