Restricting issue creation of certain types based on user project role / group

Karan Kant Mishra
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 2, 2018

Hi All,

 

We have a requirement to display hide the Issue types based on the user groups, business scenario is "We have 3 groups users, Owners, Security and 3 issue types Demand, Requirement & Feature.

1). an user who is member of the users group can create only Demand type request,

2). an user who is member of the Owners group can create Demand  & Requirement type requests.

3). an user who is the member of the security group can create only Feature type requests.

The above scenarios are achieved using the behavior plugin and works fine.

however as per the requirement, since an user can be member of more than one groups we want the issue types available to the individual groups to that user e..g if a user is member of Owner and Security then he/she should be able to submit all 3 issue types.

As per the business need the user if they do not have the right group association they should not be able to see the respective issue type at all (not the case when the user have the visibility of the Issue type and upon click on Create button on the create screen returned with an error).

Following is the script applied for the same:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.issuetype.*
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE


def userUtil = ComponentAccessor.getUserUtil()
def currentUser = ComponentAccessor.jiraAuthenticationContext.user
def issueTypeId = getFieldByName("issuetype").getValue() as String

 


if ((userUtil.getGroupNamesForUser(currentUser.name).contains("Security")) && (!userUtil.getGroupNamesForUser(currentUser.name).contains("Owners")))
{

def constantsManager = ComponentAccessor.getConstantsManager()
def DemandIssueType = constantsManager.getAllIssueTypeObjects().find { it.name == "Feature" }
getFieldById(ISSUE_TYPE).with {
setFormValue("Feature")
setReadOnly(true)
return
}

}

if ((!userUtil.getGroupNamesForUser(currentUser.name).contains("Security")) && (userUtil.getGroupNamesForUser(currentUser.name).contains("Owners")))
{

def constantsManager = ComponentAccessor.getConstantsManager()
def DemandIssueType = constantsManager.getAllIssueTypeObjects().find { it.name in [ "Demand", "Requirements" ]}

getFieldByName("issuetype").formField.setFieldOptions(DemandIssueType)
}

 

if ((!userUtil.getGroupNamesForUser(currentUser.name).contains("Security")) && (userUtil.getGroupNamesForUser(currentUser.name).contains("Owners")))
{

def constantsManager = ComponentAccessor.getConstantsManager()
def DemandIssueType = constantsManager.getAllIssueTypeObjects().find { it.name in [ "Demand", "Requirements", "Feature" ]}
getFieldByName("issuetype").formField.setFieldOptions(DemandIssueType)

}

if ((userUtil.getGroupNamesForUser(currentUser.name).contains("Security"))){
def constantsManager = ComponentAccessor.getConstantsManager()
def DemandIssueType = constantsManager.getAllIssueTypeObjects().find { it.name == "Feature" }
getFieldById(ISSUE_TYPE).with {
setFormValue("Feature")
setReadOnly(true)
}
}

 

Appreciate any help in resolving the issue.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events