Hello All,
I am using the below script to deactivate the users not logged in the last 90 days:
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.user.util.UserUtil
int numOfDays = 90 // Number of days the user was not logged in
Date dateLimit = (new Date())- numOfDays
UserUtil userUtil = ComponentAccessor.userUtil
CrowdService crowdService = ComponentAccessor.crowdService
UserService userService = ComponentAccessor.getComponent(UserService)
ApplicationUser updateUser
UserService.UpdateUserValidationResult updateUserValidationResult
long count = 0
userUtil.getUsers().findAll{it.isActive()}.each {
UserWithAttributes user = crowdService.getUserWithAttributes(it.getName())
String lastLoginMillis = user.getValue('login.lastLoginMillis')
if (lastLoginMillis?.isNumber()) {
Date d = new Date(Long.parseLong(lastLoginMillis))
if (d.before(dateLimit)) {
updateUser = ApplicationUsers.from(ImmutableUser.newUser(user).active(false).toUser())
updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid()) {
userService.updateUser(updateUserValidationResult)
log.info "Deactivated ${updateUser.name}"
count++
} else {
log.error "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}"
}
}
}
}
"${count} users deactivated.\n"
When i run this script in the console it shows 0 users are deactivated. It shows an error message in the logs with the user Email Id's.
2018-07-23 21:23:12,580 ERROR [runner.ScriptRunnerImpl]: Update of filano@hpe.com failed: Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2018-07-23 21:23:12,587 ERROR [runner.ScriptRunnerImpl]: Update of maurizio.rrato@hpe.com failed: Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2018-07-23 21:23:12,588 ERROR [runner.ScriptRunnerImpl]: Update of panick@.com failed: Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2018-07-23 21:23:12,589 ERROR [runner.ScriptRunnerImpl]: Update of prader.k.p@hpe.com failed: Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2018-07-23 21:23:12,593 ERROR [runner.ScriptRunnerImpl]: Update of manoni@hpe.com failed: Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2018-07-23 21:23:12,597 ERROR [runner.ScriptRunnerImpl]: Update of demmot@hpe.com failed: Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2018-07-23 21:23:12,600 ERROR [runner.ScriptRunnerImpl]: Update of trman@hpe.com failed: Errors: {}
Any Help would be greatly appreciated!
Thanks,
Mani
Hi @Mani
Instead of deactivating the user in the script, remove the user from the jira-users group (or any group that you have configured for the application access) in the script
Refer to https://confluence.atlassian.com/jirakb/unable-to-deactivate-users-using-deactivate-feature-in-jira-295309946.html for more details.
Hi @Mani ,
We've noticed that many users have been requesting an "Inactive User Anonymizer" feature for anonymizing users who have been inactive for a certain time. I’m pleased to inform you that our app, User Data Cleanup for Jira, includes this functionality. It allows you to easily anonymize (or in your case just deactivate) inactively or never-logged-in users based on your specified time frame.
Key features of this app include:
Highly customizable and modular: Configure multiple cleanup rules that can be applied to a single or bulk of users. Maximize control over user-specific data cleansing.
Two-Stage Cleanup: Leaving Day & Permanent: Apply a two-stage cleanup process: deactivate, remove, or transfer specific user data on the leaving day, retain necessary information for traceability, and execute a permanent cleanup.
Preview & Retrospect: Cleanup Control: Before performing cleanup actions for single or multiple users, use the Preview to check all planned actions. Use the Retrospect to check previously cleaned data for specific users.
We believe UDC can save you time and effort, and we’d love for you to give it a try. You can find more details and download our app here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.