Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,362,537
Community Members
 
Community Events
168
Community Groups

how auto pass transition when user is in specific group

Hello there,

 

i am looking for a specific need and it a little tricky for me. 

As is:

i have several JIRA project (i.e several user group, by default one group of user assign to a specific project)

i use one workflow, it is the same for my several project.

 

On my JIRA server several project used this application to handle issue.

One project use JIRA only for tracking activity and get some KPI for the manager.

 

To be:

i want to auto assign issue and pass threw a transition " taking into account" a specific state when the reporter is in my specific group.

 

To reach my goal, i have define a new listener (threw script runner) on my specific project

When a new issue is created the listener will catch it and lunch my custom script.

 

Unfortunalty, it's not working.

 

first at all , do i get the right way to reach my goal?

There is another way to implement it more easly ?

 

Please find below my source for my listener

 

import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.component.ComponentAccessor;

 

import org.apache.log4j.Category

 

log.debug("///////////////////////DEBUT RSE2I///////////////")

ApplicationUser CurrentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Issue issue = event.issue
String user = CurrentUser.toString()

log.debug("CurrentUser: " + CurrentUser.toString())
log.debug("user: " + user.toString())
log.debug("issue.reporter.name: " + user.toString())
log.debug("CurrentUser.name: " + CurrentUser.toString())

def issueManager = ComponentAccessor.getIssueManager()

def issueObject = issueManager.getIssueObject(issue.id)

 

if(issue.reporter.name == CurrentUser.name )
{

WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);

MutableIssue parent = issue.getParentObject() as MutableIssue

workflowTransitionUtil.setAction(11);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();

issueObject.setAssignee(CurrentUser)

}

 

I never reach my log line, i get an error define below:

 

018-08-08 15:10:49,124 http-nio-8080-exec-33 ERROR Olivier.mazen@orange.com 910x32284x1 1jj978s 10.186.1.234,10.115.64.201,127.0.0.1 /secure/QuickCreateIssue.jspa [c.o.scriptrunner.runner.AbstractScriptListener] Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException
	at com.atlassian.jira.security.DefaultPermissionManager.doIssuePermissionCheck(DefaultPermissionManager.java:133)
	at com.atlassian.jira.security.DefaultPermissionManager.hasPermission(DefaultPermissionManager.java:86)
	at com.atlassian.jira.security.WorkflowBasedPermissionManager.hasPermission(WorkflowBasedPermissionManager.java:82)
	at com.atlassian.jira.security.ApplicationRequiredPermissionManager.lambda$hasPermission$1(ApplicationRequiredPermissionManager.java:76)
	at com.atlassian.jira.security.ApplicationRequiredPermissionManager.checkUserHasApplicationOrFalse(ApplicationRequiredPermissionManager.java:182)
	at com.atlassian.jira.security.ApplicationRequiredPermissionManager.hasPermission(ApplicationRequiredPermissionManager.java:76)
	at com.atlassian.jira.security.PublicAccessPermissionManager.lambda$hasPermission$1(PublicAccessPermissionManager.java:80)
	at com.atlassian.jira.security.PublicAccessPermissionManager.checkPublicAccessEnabledOrDelegate(PublicAccessPermissionManager.java:188)
	at com.atlassian.jira.security.PublicAccessPermissionManager.hasPermission(PublicAccessPermissionManager.java:80)
	at com.atlassian.jira.config.component.SwitchingInvocationHandler.invoke(SwitchingInvocationHandler.java:22)
	at com.sun.proxy.$Proxy13.hasPermission(Unknown Source)
	at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.hasTransitionPermission(WorkflowTransitionUtilImpl.java:373)
	at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.validateTransitionPermission(WorkflowTransitionUtilImpl.java:299)
	at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.access$300(WorkflowTransitionUtilImpl.java:37)
	at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl$2.get(WorkflowTransitionUtilImpl.java:241)
	at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl$2.get(WorkflowTransitionUtilImpl.java:236)
	at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.impersonateUser(WorkflowTransitionUtilImpl.java:380)
	at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.validate(WorkflowTransitionUtilImpl.java:236)
	at com.atlassian.jira.workflow.WorkflowTransitionUtil$validate$1.call(Unknown Source)
	at Script208.run(Script208.groovy:42)

I didn"t get why is triggering the error, if you have any idea?

 

Thanks in advance !

 

Olivier

2 answers

1 accepted

0 votes
Answer accepted

Hello,

 

i have reach my goal by using a fast track transition.

 

In condition i get if the user is in the specify group.

 

in more action is set the assagnee value to my user.

Hello every one,

 

i reduce my scope of investigation.

In my listener: i have set the follow code:

 

import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.component.ComponentAccessor;
import org.apache.log4j.Category
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.workflow.TransitionOptions

Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)

ApplicationUser CurrentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Issue issue = event.issue

def issueService = ComponentAccessor.getIssueService()
def issueManager = ComponentAccessor.getIssueManager()
def issueObject = issueManager.getIssueObject(issue.id)
def groupeRSE2I = ComponentAccessor.groupManager.getGroup("RSE2I")


log.debug("///////////////////////DEBUT RSE2I///////////////")
//log.debug("CurrentUser: " + CurrentUser.toString())

log.debug("issue.reporter.name: " + issue.reporter.name.toString())
//log.debug("CurrentUser.name: " + CurrentUser.toString())

log.debug("Appartient au groupe: " + ComponentAccessor.groupManager.getUserNamesInGroup(groupeRSE2I).contains(issue.reporter.username))

if(ComponentAccessor.groupManager.getUserNamesInGroup(groupeRSE2I).contains(issue.reporter.username))
{

log.debug("Dans le if")

WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);


log.debug("apres WF")


MutableIssue parent = issue.getParentObject() as MutableIssue


log.debug("apres parent")

workflowTransitionUtil.setAction(11);

log.debug("apres setaction")
workflowTransitionUtil.validate();

log.debug("apres validate")
workflowTransitionUtil.progress();

log.debug("apres progress")


def issueInputParameters = issueService.newIssueInputParameters()

log.debug("apres issueInputParameters")

issueInputParameters.with
{
setSkipScreenCheck(true)
}

def transitionOptions= new TransitionOptions.Builder()
.skipPermissions()
.skipConditions()
.skipValidators()
.build()

log.debug("apres transition option")

def validationResult = issueService.validateTransition(CurrentUser, event.issue.id, 11, issueInputParameters, transitionOptions)

log.debug("apres validationresult")


if (validationResult.isValid())
{

log.debug("dans le isvalide")
def issueResult = issueService.transition(CurrentUser, validationResult)
}
else {
for (String message in validationResult.errorCollection.errorMessages) {
log.warn("Could not transition task ${event.issue.key}, errors: ${message}")
}
log.warn("Could not transition task ${event.issue.key}, errors: ${validationResult.errorCollection}")
}

log.debug("apres isvalide")

issueObject.setAssignee(CurrentUser)
log.debug("apres setassagnee")
ComponentAccessor.getIssueManager().updateIssue(CurrentUser, issueObject, EventDispatchOption.ISSUE_UPDATED, false)

log.debug("apres UPD issue")
}

log.debug("///////////////////////FIN RSE2I///////////////")

 

Here is the log associate :

///////////////////////DEBUT RSE2I///////////////
2018-08-13 09:29:41,903 http-nio-8080-exec-65 DEBUG Olivier.mazen@orange.com 569x29373x1 1nnzdy6 10.186.1.234,10.115.64.201,127.0.0.1 /secure/CreateIssueDetails.jspa [c.onresolve.jira.groovy] issue.reporter.name: Olivier.mazen@orange.com
2018-08-13 09:29:41,903 http-nio-8080-exec-65 DEBUG Olivier.mazen@orange.com 569x29373x1 1nnzdy6 10.186.1.234,10.115.64.201,127.0.0.1 /secure/CreateIssueDetails.jspa [c.onresolve.jira.groovy] Appartient au groupe: true
2018-08-13 09:29:41,903 http-nio-8080-exec-65 DEBUG Olivier.mazen@orange.com 569x29373x1 1nnzdy6 10.186.1.234,10.115.64.201,127.0.0.1 /secure/CreateIssueDetails.jspa [c.onresolve.jira.groovy] Dans le if
2018-08-13 09:29:41,904 http-nio-8080-exec-65 DEBUG Olivier.mazen@orange.com 569x29373x1 1nnzdy6 10.186.1.234,10.115.64.201,127.0.0.1 /secure/CreateIssueDetails.jspa [c.onresolve.jira.groovy] apres WF
2018-08-13 09:29:41,904 http-nio-8080-exec-65 DEBUG Olivier.mazen@orange.com 569x29373x1 1nnzdy6 10.186.1.234,10.115.64.201,127.0.0.1 /secure/CreateIssueDetails.jspa [c.onresolve.jira.groovy] apres parent
2018-08-13 09:29:41,904 http-nio-8080-exec-65 DEBUG Olivier.mazen@orange.com 569x29373x1 1nnzdy6 10.186.1.234,10.115.64.201,127.0.0.1 /secure/CreateIssueDetails.jspa [c.onresolve.jira.groovy] apres setaction
2018-08-13 09:29:41,904 http-nio-8080-exec-65 DEBUG Olivier.mazen@orange.com 569x29373x1 1nnzdy6 10.186.1.234,10.115.64.201,127.0.0.1 /secure/CreateIssueDetails.jspa [c.onresolve.jira.groovy] apres validate
2018-08-13 09:29:41,907 http-nio-8080-exec-65 ERROR Olivier.mazen@orange.com 569x29373x1 1nnzdy6 10.186.1.234,10.115.64.201,127.0.0.1 /secure/CreateIssueDetails.jspa [c.o.scriptrunner.runner.AbstractScriptListener] *************************************************************************************
2018-08-13 09:29:41,907 http-nio-8080-exec-65 ERROR Olivier.mazen@orange.com 569x29373x1 1nnzdy6 10.186.1.234,10.115.64.201,127.0.0.1 /secure/CreateIssueDetails.jspa [c.o.scriptrunner.runner.AbstractScriptListener] Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException
 at com.atlassian.jira.security.DefaultPermissionManager.doIssuePermissionCheck(DefaultPermissionManager.java:133)
 at com.atlassian.jira.security.DefaultPermissionManager.hasPermission(DefaultPermissionManager.java:86)
 at com.atlassian.jira.security.WorkflowBasedPermissionManager.hasPermission(WorkflowBasedPermissionManager.java:82)
 at com.atlassian.jira.security.ApplicationRequiredPermissionManager.lambda$hasPermission$1(ApplicationRequiredPermissionManager.java:76)
 at com.atlassian.jira.security.ApplicationRequiredPermissionManager.checkUserHasApplicationOrFalse(ApplicationRequiredPermissionManager.java:182)
 at com.atlassian.jira.security.ApplicationRequiredPermissionManager.hasPermission(ApplicationRequiredPermissionManager.java:76)
 at com.atlassian.jira.security.PublicAccessPermissionManager.lambda$hasPermission$1(PublicAccessPermissionManager.java:80)
 at com.atlassian.jira.security.PublicAccessPermissionManager.checkPublicAccessEnabledOrDelegate(PublicAccessPermissionManager.java:188)
 at com.atlassian.jira.security.PublicAccessPermissionManager.hasPermission(PublicAccessPermissionManager.java:80)
 at com.atlassian.jira.config.component.SwitchingInvocationHandler.invoke(SwitchingInvocationHandler.java:22)
 at com.sun.proxy.$Proxy11.hasPermission(Unknown Source)
 at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.hasTransitionPermission(WorkflowTransitionUtilImpl.java:373)
 at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.retrieveActionDescriptorWithPermissionCheck(WorkflowTransitionUtilImpl.java:141)
 at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.getActionDescriptor(WorkflowTransitionUtilImpl.java:133)
 at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.hasScreen(WorkflowTransitionUtilImpl.java:361)
 at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.progress(WorkflowTransitionUtilImpl.java:338)
 at com.atlassian.jira.workflow.WorkflowTransitionUtil$progress$1.call(Unknown Source)
 at Script489.run(Script489.groovy:56)


 

I can reach the the setaction but it's look like the commande workflowTransitionUtil.progress();

doesn't seems to work.

 

Does anyone know why ?

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events