Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Help w/scriptrunner listener for adding a user to a group after removed from jira-software-users

Michael
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2024

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

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Javier Martínez Caballero
Contributor
October 22, 2024

 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

TAGS
AUG Leaders

Atlassian Community Events