I have a script that I use to add and remove users from groups. At the start of the script, I call
ComponentAccessor.getGroupManager().getGroupNamesForUser(user)
to get the current list of groups for the user. After I have added and/or removed groups, I call it again. Instead of showing the new list of groups, I get the same list that I received from the first call.
It appears to me that this is either calling an index or a cache that is not being refreshed. However, when I look at the user in the User Management view, I can see that the correct actions have been taken.
Any suggestions on what call I should be making in conjunction or instead of this approach?
GroupManager has an internal request cache of user group membership, this cache is not updated when group membership changes occur, see the following bug: JRASERVER-63095
There isn't a good workaround for this, but if you really need to see the updated memberships in the same request, you can forcibly clear all request caches, which will also clear the cache in GroupManager.
In ScriptRunner you could do that with the following code:
import com.atlassian.jira.cache.request.RequestCacheController
RequestCacheController.clearAll()
The above code could have performance implications because it forces request caches to be cleared/recomputed, but I do not know of a better solution for this problem.
Cheers,
Reece
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.