How do I anonymize issue creation in post function via scriptrunner

Mark Butterfield July 13, 2016

How can I assign a default user when creating a new issue so that the history log displays "<default user> created issue"

  1. I should have stated my question more clearly. How do I programatically assign the currentUser to a predetermined user ( "defaultReporter" for example ) to really anonymize ticket creation when a logged in user creates a new issue. I am using scriptrunner and a post function/custom script in the create transition.

    I can assign a default reporter, but the current user is still visable in the History or All tab of the issue. There it is documented who actually created the ticket. I need the functionallity to work for logged in users.

    Thanks..

2 answers

1 accepted

0 votes
Answer accepted
Mark Butterfield July 15, 2016

Actually I was able to resolve the issue myself with the following code..

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.JiraAuthenticationContext;
def us = ComponentAccessor.getUserUtil().getUserByName("Anonymous").getDirectoryUser();
def ac = ComponentAccessor.getJiraAuthenticationContext();
ac.setLoggedInUser(us);
issue.setReporter(us);

and it functions fine in the Create Issue transition, it is actually the first script to be called in the post functions. The assignment of LoggedInUser solved the issue of creator anonymity in the tabs History and All.

JamieA
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.
July 19, 2016

That means you have a real user called Anonymous... that's not quite the same.

mark butterfield July 20, 2016

Actually I have to agree...went back and found the method clearLoggedInUser() in JiraAuthenticationContext which I had missed before. I have now just left the Reporter as optional and then set as hidden, in the post function I now just call ac.clearLoggedInUser() and the issue is then actually anonymous.

Thanks for the comment, got me to go back and check again...you could have just pointed out the clearLoggedInUser() method though.

JamieA
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.
July 20, 2016

I probably would have, but I thought you were happy with your solution. If you want tips, it seems like you use a try/finally block, and replace the actual logged in user. Otherwise I think this user would require to log in again.

Mark Butterfield July 20, 2016

Actually the user remains logged in. Also even if I am happy with the solution..I am even happier to find a more correct solution or other options. Also it is helpful for others searching for solutions if an expert points out short-commings or suggests other solutions..so Please comment when you can! Thanks again!

0 votes
GabrielleJ
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.
July 14, 2016

Find an add-on that can create a JIRA Issue OR will allow you to run a script that will create the JIRA issue then just use the default assignee as the reporter.

Mark Butterfield July 14, 2016

I should have stated my question more clearly. How do I programatically assign the currentUser to a predetermined user ( "defaultReporter" for example ) to really anonymize ticket creation when a logged in user creates a new issue. I am using scriptrunner and a post function/custom script in the create transition.

I can assign a default reporter, but the current user is still visable in the History or All tab of the issue. There it is documented who actually created the ticket. I need the functionallity to work for logged in users.

Thanks..

GabrielleJ
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.
July 14, 2016

This means that the Post-function you have put will be ran after the ticket has been created. What you need to do here is to create the ticket not via the post-function. The ticket must be created outside the post-function. You cannot even put your post-function before the "Create the issue" because there's nothing to update if you put that after anything else.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events