3

I want to create a workflow validator which will not allow the reporter of the issue to execute certain steps from the workflow. For that purpose somehow I have to get the User object or the user id of the user executing the action. How can I do that?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Svetlin Zarev
  • 14,713
  • 4
  • 53
  • 82

2 Answers2

1

inject the JiraAuthenticationContext And then call jiraAuthenticationContext.getLoggedInUser();

you can find the documentation about the JiraAuthenticationContext here: https://docs.atlassian.com/jira/5.0.1/com/atlassian/jira/security/JiraAuthenticationContext.html

Lama
  • 2,886
  • 6
  • 43
  • 59
  • I'm accepting your answer, although I'll left it as is now with my solution :) – Svetlin Zarev Nov 10 '15 at 13:54
  • Thanks! :) I recommend you stick with the atlassian API way, so there won't be any problems - e.g. in case of a minor upgrade of your jira instance. – Lama Nov 10 '15 at 13:55
0

Here is how I've managed to do it:

private String getCurrentIssueProcessorId(Map<?, ?> transientVars, Map<?, ?> args){
        String processorId = (String) args.get(ARG_USER_NAME);
        if(null == processorId || processorId.isEmpty()){
            WorkflowContext workflowContext = (WorkflowContext) transientVars.get(ARG_CONTEXT);
            processorId = workflowContext.getCaller();
        }

        if(logger.isDebugEnabled()){
            logger.debug("Issue processor: " + processorId);
        }

        return processorId;
}

where ARG_CONTEXT is the string context and ARG_USER_NAME is the string username

Svetlin Zarev
  • 14,713
  • 4
  • 53
  • 82