Forums

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

How to deactivate user accounts

Derrick Wong
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 15, 2019

I followed this https://confluence.atlassian.com/adminjiraserver/create-edit-or-remove-a-user-938847025.html

 

however I don't see an "active" checkbox in the user profile page.

2 answers

0 votes
Bunty
Contributor
May 15, 2019

If you have script runner add-on installed, use the below script to deactivate the users,

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes

import org.apache.log4j.Level
log.setLevel(Level.INFO)

def numOfDays = 90 as int
def dateLimit = ( new Date() ) - numOfDays

def groupManager = ComponentAccessor.groupManager
def crowdService = ComponentAccessor.crowdService
def userManager = ComponentAccessor.userManager
def userUtil = ComponentAccessor.userUtil

def const_groupname = 'jira-users'
def group = groupManager.getGroup(const_groupname)
def groupMembers = groupManager.getDirectUsersInGroup(group)

def counter = 0 as int
groupMembers.each{ applicationUser ->

if( applicationUser.isActive() ){
def user = crowdService.getUserWithAttributes( applicationUser.name ) as UserWithAttributes
def lastLoginMillis = user.getValue('login.lastLoginMillis') as String

if( lastLoginMillis?.isNumber() ){
def date = new Date(Long.parseLong(lastLoginMillis)) as Date
if( date.before(dateLimit) ){
counter++
userUtil.removeUserFromGroup(group, applicationUser)
}
}
}
}

log.info "Removed ${counter} users"

0 votes
Jack Brickey
Community Champion
May 15, 2019

Are you on Server Version 8.1?

Suggest an answer

Log in or Sign up to answer