How to retrieve users use for transition permissions check in condition?

Roberto Saltini March 2, 2017

Hi,

I am basically trying to execute a transition as if it was execute by a user different from the one currently logged in.

Considering the following:

  • The current logged in user is "userA"
  • "userA" modifies a field which via a listener executes the following automatic transition:

    def UserManager userManager = ComponentAccessor.getUserManager()
    ApplicationUser user = userManager.getUserByName("jira")
    
    IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(
            user,issue.id, actionId,new IssueInputParametersImpl([:])
    )
    
    //if(true)
    if(! transitionValidationResult.errorCollection.hasAnyErrors())
    {
        log.debug("Transition Successful")
        issueService.transition(user,transitionValidationResult)
        return true
    }
    else
    {
        log.debug("Transition Error: ${transitionValidationResult.errorCollection.toString()}")
        return false
    }

    Please note that he transition is called using the user "jira" rather than the currenty logged in user ("userA")


Now, in the condition of the transition corresponding to "actionid"  I would like to be able to know which was the user used as parameter of validateTransition(). Referring to my example, this would give as a result the user "jira".

If I use either

((WorkflowContext) transientVars.get("context")).getCaller();

or

ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

I get as result the user "userA" not "jira"

 

Thanks.

4 answers

0 votes
Dmitriy_Khalturin September 21, 2017

You can use 

ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(user)

before issueService.validateTransition(...)

0 votes
Gonchik Tsymzhitov September 20, 2017

Hi! 

May I know did you find a solution for your question? 

0 votes
Roberto Saltini March 6, 2017

Niclas Sandström [Riada] I have expanded the question. Hope now it is clear.

0 votes
Niclas Sandstroem
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.
March 3, 2017

I don't really follow here could you explain a bit more?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events