Hello. I'm trying to provide a feature to our Jira users, which can show them, who can act on an issue in it's current state.
My idea is to show a list of transitions which are possible from current status and workflow and to give a list of users which can perform these transitions.
So, users who are stucked with an issue can check who can help out.
Unfortunately i did not come very far. I only came down to the place where is have the step (associated with the status) and the actions available at this step.
I have absolutely no idea, how to retrieve any further information about the actions and their conditions, to finally break them down to user names.
My code so far looks like this (as a starting point):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.WorkflowManager
import com.opensymphony.workflow.loader.*
def issue = ComponentAccessor.getIssueManager().getIssueObject("XXX-123")
def workflowManager = ComponentAccessor.getComponentOfType( WorkflowManager.class )
def issueWorkflow = workflowManager.getWorkflow(issue)
def issueStatus = issue.getStatus()
//issueWorkflow.getName()
log.warn(issueStatus.getName())
def issueStep = issueWorkflow.getLinkedStep(issueStatus)
for (def act: issueStep.getActions()){
log.warn(' action:'+act.getName())
}
I would have thought, that these objects (to be retrieved by JiraWorkflow getters) would help, but i'm lost:
com.opensymphony.workflow.loader.ActionDescriptor
com.opensymphony.workflow.loader.StepDescriptor
...
Sorry, if my question does not look highly experienced. I'm not a Java/Groovy expert but until now was able to resolve most tasks with ScriptRunner.
Kind regards
Klaus
Thanks to Tom's final hint, i was able to find the way through.
It seems like an action does have exactly ONE Restriction (getRestrictions()), which points toa ConditionsDescriptor (getConditions()), where one can walk through by getConditions() in order to get a map of 'class.name' (com.atlassian.jira.workflow.condition) and a "named" argument + value (e.g. com.atlassian.jira.workflow.condition.UserInGroupCondition => group:a_group_name)
The according code snippet looks like this:
for (def act: issueStep.getActions()){
transitionUsers += '<br><b>'+act.getName()+'</b>:'
def rest = act.getRestriction()
if (rest){
def restrictionUsers=[]
def cons = rest.getConditionsDescriptor();
for (def cond: cons.getConditions()){
// conditions: a map of: class.name => named argument
// e.g. class.name:....UserInGroupCondition => group:...
// now get the "basename" of class.name
def className = cond.getArgs()['class.name'].tokenize('.').last()
switch (className){
case 'AllowOnlyAssignee': if (issue.getAssignee()){
restrictionUsers.add(issue.getAssignee())
}
break
case 'AllowOnlyReporter': restrictionUsers.add(issue.getReporter())
break
case 'UserInGroupCondition': restrictionUsers.addAll(ComponentAccessor.getComponentOfType( GroupManager.class ).getUsersInGroup(cond.getArgs()['group']))
break
case 'InProjectRoleCondition': restrictionUsers.addAll(getProjectRoleUsers(issue.getProjectObject(), cond.getArgs()['jira.projectrole.id'].toLong()))
break
}
}
Sorry for the unformatted paste. No idea why i can't take over indenting.
I have no answer to this but I think it will be difficult to achieve. The permission API's in general check from the point of view of the logged in user as the entry point.
You would need to check conditions defined for workflow transitions and look for groups and role conditions and find users who match those conditions. Also need to check permissions scheme for ability to transition issues.
I'd advise some more procedural approach to escalate to a person who has ability to reassign. Or notify a team group defined by issue type or other criteria.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tom.
I totally agree with you, that it might not become very easy for exactly the reason you mentioned. Methods described here https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/workflow/IssueWorkflowManager.html would be perfect to simply check a a particular user.
The detour about conditions and roles/groups is exactly what i had in mind.
But, as stated above, i'm missing the linking package/method for retrieving the conditions.
Any hint?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
here is a Java snippet that gets actions and permissions
StepDescriptor issueStep = issueWorkflow.getLinkedStep(issueStatus);
List<PermissionDescriptor> perms = issueStep.getPermissions();
List<ActionDescriptor> actions = issueStep.getActions();
for (ActionDescriptor act : actions) {
log.warn(" action: " + act.getName());
}
for (PermissionDescriptor perm : perms) {
log.warn(" action: " + perm.getName());
}
Hope it helps you progress a bit further.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tom.
Thank you very much for contributing.
The problem is, i forgot to mention - since i forgot that i have tried already - that getPermissions() does not return anything in my case.
Even though i'm sure the issue belongs to a workflow in a status where permissions apply for all outgoing transitions.
I think, it's not the permission on the step, which is of interest here. I'm convinced it must be a condition (e.g. AllowOnlyAssignee) being applied to the transitionwhat i'm looking for.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's not clear from the api docs how this is structured. I can only suggest exploring what the API is returning from the action descriptor. I'd ignore system permissions.
for (ActionDescriptor act : actions) {
log.warn(" action: " + act.getName());
List<ActionDescriptor> per = act.getPreFunctions();
RestrictionDescriptor rest = act.getRestriction();
ConditionsDescriptor cond = rest.getConditionsDescriptor();
List<ConditionsDescriptor> cons = cond.getConditions();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Correct. The structure is unclear to me as well, what might be the reason for not finding the way through.
Anyway. Thanks for your time and contribution.
At least i have learned, that it's not only me who is a bit clueless here ;-)
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.
Hi Aleksandr,
no i haven't see it before, but it's exactly how far i am as well. I mean i already have the list of possible transitions out of the current state.
My problem is, that i simply can't find any method to determine conditions which apply to these transitions now.
There's the package com.atlassian.jira.workflow.condition which handles the conditions available to the workflow editor, but i don't know how to get this in my code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.