Hi all,
I'm trying to find which applications (software, service desk, confluence) are accessible by newly created user. I tried to use ScriptListener from ScriptRunner to access it using "UserCreatedEvent". So when a user is newly created, it listens to the event, then get a username of new user to find which applications are accessible from the user. but it seems it's not getting the applications associated with the new user correctly.
From the code below, I only tried to check if JIRA software application is accessible by this new user. I tested with a newly created user with software access but it couldn't get the correct data. But when I tested with my existing users, it works just fine.
Thank you so much in advance,
Here is my code:
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.AbstractEvent
import com.atlassian.crowd.event.user.UserCreatedEvent
import com.atlassian.jira.application.ApplicationAuthorizationService
import com.atlassian.jira.application.ApplicationKeys
import com.atlassian.jira.component.ComponentAccessor
def newUserEvent = event as UserCreatedEvent;
def newUser = newUserEvent.getUser();
def newUserEmail = newUser.getEmailAddress();
def joinedGroup = "";
def applicationAuthorizationService = ComponentAccessor.getComponent(ApplicationAuthorizationService)
def userManager = ComponentAccessor.userManager
def user = userManager.getUserByName(newUser.getName());
if (applicationAuthorizationService.canUseApplication(user, ApplicationKeys.SOFTWARE)) {
joinedGroup = "JIRA Software";
}else {
joinedGroup = "somethingelse";
}
true