Hi all,
We are trying to figure out how to create a scriptrunner listener for our Jira Data-Center instance which will add a user to our "deactivated-users" user group when they are removed from the "jira-software-users" user group but are still "Active" and not "Disabled".
Some background:
Currently, we have an "auto-deactivator" plugin which removes users from the jira-software-users group if they don't log in within "x" amount of days to save on licenses. (But still keeps them "active" within our jira directory)
If anyone has a scriptrunner listener code for this, or can point us in the correct direction, we'd greatly appreciate it.
Thanks,
Mike
Hi Mike,
The listener should trigger when a user is removed from the "jira-software-users" group, and then check if they are still "Active." If so, the user should be added to the "deactivated-users" group.
Here’s a sample Groovy script that should help:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.user.UserEvent
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.crowd.embedded.api.Group
def userManager = ComponentAccessor.getUserManager()
def groupManager = ComponentAccessor.getGroupManager()
def event = event as UserEvent
def user = event.getUser() as ApplicationUser
// Define your groups
def jiraSoftwareGroup = groupManager.getGroup("jira-software-users")
def deactivatedGroup = groupManager.getGroup("deactivated-users")
// Check if the user was removed from the jira-software-users group
if (event.eventTypeId == UserEvent.REMOVED_FROM_GROUP && event.groupName == "jira-software-users") {
// Verify the user is still active and not disabled
if (userManager.isUserActive(user)) {
// Add the user to the deactivated-users group
if (!groupManager.isUserInGroup(user, deactivatedGroup)) {
groupManager.addUserToGroup(user, deactivatedGroup)
log.debug("User ${user.getUsername()} added to deactivated-users group.")
}
}
}
This should automate the process and help manage users effectively.
Let me know how it goes or if you need further tweaks!
Best regards,
Javier
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.