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:
Can someone help me? I can not get it to work.
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
}
Thanks Howard. It worked with your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.