While Auditing users added from portal we check to ensure they are in a specified group.
If a new user is created we run a script against to add the user to the group but then further checks that the user is in the group then fail until the script is restarted.
The following is a sample of what I'm working with:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.crowd.embedded.api.Group
UserManager userManager = ComponentAccessor.getUserManager() as UserManager
ApplicationUser testUser
testUser = userManager.getUserByKey("JIRAUSER35000")
def groupManager = ComponentAccessor.groupManager
def usersGroups = groupManager.getGroupNamesForUser(testUser.username)
Group addToGroup = groupManager.getGroup('SC-ALL USERS')
addToGroup.add(testUser)
usersGroups = groupManager.getGroupNamesForUser(testUser.username)
I would expect the last userGroups value to contain the group that the user has just been added to.
What am I missing?