Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Groovy postfunction / Confluence SQL Pro: Strange problem with getting usernames programmatically

Richard Schaeffer October 9, 2015

I have a groovy postfunction in place that creates a subtask.  For the most part, this works, but it fails in the case where I have a user that has had their username modified.  For example, if I have a user 'jraub@company.com', but his username was initially 'jraub', my code returns 'jraub' and the validateSubTaskCreate() fails.

 

This problem also presents itself in my SQL reports for Confluence - when I do joins with the jiraissue table, the username related fields (assignee, reporter) always have the original 'jraub' value.  Same thing with the change history related tables. 

 

I've been reverting usernames as a workaround (only a few users affected), but I'll need to change every username on our JIRA shortly and this problem must be addressed.  Can anyone offer any insight?

 

Thanks!

 

Here's a snippet of my code: 

 

User user = ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser();

ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(user);

CreateValidationResult createValidationResult = issueService.validateSubTaskCreate(user, issue.getId(), issueInputParameters);

log.error("errors (1): " +     createValidationResult.getErrorCollection().getErrorMessages());

for(String error : createValidationResult.getErrorCollection().getErrors().values()){

    log.error(error);

}

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
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.
October 12, 2015

This line doesn't do anything useful AFAIK, remove it:
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(user);

Replace

User user = ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser()

with

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

0 votes
Richard Schaeffer October 16, 2015

Sorry about the delay - that solution worked.

 

I also solved the MySQL issue - for anyone interested, there is an "app_user" table that maps the original username to the current one for those that have been changed.

0 votes
Richard Schaeffer October 12, 2015

1. Yes, that's correct. 2. user 'jraub' does not exist (or something to that effect, I'm out of office today).

0 votes
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.
October 11, 2015

> my code returns 'jraub' which bit of your code, the getDirectoryUser() ? > and the validateSubTaskCreate() fails. can you include the validation messages

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events