Separation of Duties

Deleted user May 9, 2018

I want to create a validator which allows a transition in case user is member of Administrators or Product Owner and if not checks that the user did not request the ticket itself.

 

So I want to extend:

https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/conditions/simple-scripted-condition.html#_separation_of_duties

Can someone help me? I can not get it to work.

1 answer

1 accepted

0 votes
Answer accepted
JohnsonHoward
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 9, 2018

Hi Daniel,

I suggest using a Condition for this, not a validator as a validator is generally used to validate the data on the form. Conditions are used to show transitions based on certain values so this seems more suited to your use case.

In this case you don't need to extend that example to get what you need. All you need to do is check the user is either set as an Administrator or Product Owner. Then check if the user matches the reporter if not. 

I have provided an examples below, it is untested but has all the values you need there. Play around with this script to get the result that you need. For conditions you need to assign a boolean value to the 'passesCondition' variable to say if the transition should be shown or not. You can see that I have done this here: 

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

Issue issue = issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class)
def adminRole = projectRoleManager.getProjectRole("Administrators")
def productOwnerRole = projectRoleManager.getProjectRole("Product Owner")
def isAdmin = projectRoleManager.isUserInProjectRole(currentUser, adminRole, issue.getProjectObject())
def isProductOwner = projectRoleManager.isUserInProjectRole(currentUser, productOwnerRole, issue.getProjectObject())
def reporter = issue.reporter

if((!isAdmin || !isProductOwner) && reporter.username != currentUser.username){
passesCondition = false
Deleted user May 9, 2018

Thanks Howard. It worked with your help.

Ricardo Cereceres February 19, 2025

Hello, Howard, 

Do you know how can I create a script like this but for preventing a user from executing a transition if the user have already performed a specific transition on the issue before? 

JohnsonHoward
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.
February 20, 2025

Hi Ricardo, I have since moved away from Atlassian Community work but I can advise using the Issue change log class to find the information you are looking for and then preventing the transition.

Take a look at  https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/changehistory/ChangeHistoryManager.html

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events