Can the Simple Scripted Validator be used to allow only users in a specific project role to create an issue?

Jeff Peters November 17, 2015

Good day.

I am a jira-administrator and have a project that has four issuetypes.  Three of the issueypes may be created by jira-users, who have been granted Create permissions in the project's Permission Scheme.  However, the fourth issuetype needs to limit the reporter to the member of a project role group (e.g., Generic Role 4).  Can the Simple Scripted Validator be used for this purpose?  If so, what would the script look like?

I am aware of the following sample script, but I believe it is only for JIRA instance groups.

 

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.getGroupManager()
groupManager.isUserInGroup(issue.reporter?.name, 'business-users')

 

We are using Script Runner v3.0.16.

 

Many thanks for your assistance!

2 answers

5 votes
Thanos Batagiannis _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.
November 18, 2015

Hi Jeff,

I think in your case you can use the projectRoleManager, it should be something like this 

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

def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName(issue.reporter?.name)
def projectRoleManager = (ProjectRoleManager) ComponentAccessor.getComponentOfType(ProjectRoleManager.class);
// name of role here
def devsRole = projectRoleManager.getProjectRole("Developers")
return projectRoleManager.isUserInProjectRole(user, devsRole, issue.getProjectObject())

Hope this helps. 

Melina Maquieyra June 10, 2020

Hi, I need the same script but with two Project Roles. How I do? Thanks

1 vote
Jeff Peters November 18, 2015

Thanos,

 

You Totally ROCK!

Your work was spot-on and HIGHLY appreciated!

 

Many thanks again for your help!

 

Cheers.

P.S.  Please give my fond regards to Jamie when you see him next.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events