Jira user management - Disabling the inactive users with no activity for past 90 days

Darshan Deshmukh June 4, 2019

Hi All,

We are using Jira - 7.7.4 (Commercial - Data Center) [Approximately 4000 users]

[Update 8.2.1 is available]

Use case - We want to delete the inactive users(not looged in since last 90 days) from the system. 

Problem - Currently Jira shows that all my 4000 users are active (this also includes the users which never logged in)

Reason - We only have a limit for 5000 users and we cant add any more users once we reach that limit.

Does Jira already has support for this to do it via REST API? OR We need to create an automation script for this to filter and delete the users from backend?

Suggestions are welcome if anyone has already explored on this problem. 

 

3 answers

2 accepted

1 vote
Answer accepted
Ben Poulson
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.
June 4, 2019

Wrote a groovy script to do it- if you have scriptrunner installed, you can set it as an escalation service to run on whatever schedule you want

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.UserService
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.security.login.LoginManager
import com.atlassian.jira.bc.security.login.LoginInfo
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.crowd.embedded.api.User


UserManager userManager = ComponentAccessor.getUserManager()
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
UserService userService = ComponentAccessor.getComponent(UserService)
ApplicationUser updateUser
UserService.UpdateUserValidationResult updateUserValidationResult
def users = userManager.getUsers().findAll{user -> (user.isActive())}
for (user in users)
{
def lastLoginMillis = loginManager.getLoginInfo(user.name).getLastLoginTime()
def disable = false
if(!lastLoginMillis)
{
//user has never logged in
disable = true
}
else
{
Date cutoff = new Date().minus(90)
Date last = new Date(lastLoginMillis)
if(last.before(cutoff))
{
disable = true
}
}
if(disable == true)
{
def userAsImmutable = new ImmutableUser(user.directoryId, user.name, user.displayName, user.emailAddress, false)
updateUser = ApplicationUsers.from(userAsImmutable)
updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid())
{
userService.updateUser(updateUserValidationResult)
log.info "Deactivated ${updateUser.name}"
}
else
{
log.error "Failed to deactivate ${updateUser.name}"
}
}
}
Darshan Deshmukh June 4, 2019

@Ben Poulson Thanks Ben. Let me test this and update on this thread.  

Thorat_ Nikesh April 19, 2021

Is it working ? if no then, is there any way from SQL DB to achieve this result ? 

Ramondrio Imanuel June 10, 2021

Hi @Ben Poulson ,

 

Is this script can work in Jira Cloud?

0 votes
Answer accepted
Petr Vaníček
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.
June 4, 2019

Hi,

in that case I have experience with this add-on for Jira. Disabling of inactive users is only one of features.

https://marketplace.atlassian.com/apps/1217194/optimizer-for-jira-cleaner-for-jira?hosting=server&tab=overview

Darshan Deshmukh June 4, 2019

Thanks @Petr Vaníček This is really useful but ideally I would like to call a REST API to delete these users from my automation script so that I can run it at the predefined time interval without any human intervention.

Do you have any working example to do this activity via REST calls?  

1 vote
Mahima_miniOrange_SSO
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
April 19, 2021

Hello @Darshan Deshmukh  ,

This is Mahima from miniOrange.

If you are looking for plugin which can fulfill your requirements, I would like to suggest you User Management Plugin which can automatically deactivate the users who have never logged in or who have not been active since past 90 days or any other time period, which can help you to manage your users easily in just one click.

Feel free to reach out to us at atlassiansupport@xecurify.com or you can raise the ticket in case you need any help!

Cheers,

Mahima

Suggest an answer

Log in or Sign up to answer