Remove a specified user from a group using this snippet, meaning they no longer have the permissions associated with the group. For example, if a Jira admin has left a project, use this snippet to remove them from the group with access rights to the project they left.
I want to ensure users only have access to the projects they are working on currently, enforcing the principle of least privilege. Use this script alongside the Deactivate Idle Users’ script to show inactive users, and use the ‘Remove Specified Users from a Group’ script to remove them from the groups they no longer need access to.
Good to Know
There are two ways that you can use this script: from the ScriptRunner Console as a single script, or as part of a more complex script facilitating other features in ScriptRunner for Jira.
// the group you want to remove users from
final String groupName = "Group_A"
// user names of the users to remove
final List usersToRemove = ["user_A", "user_B"]
def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
def group = ComponentAccessor.groupManager.getGroup(groupName)
assert group : "Could not find group with name $groupName"
def userToRemove = userManager.getUserByName(it)