Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created October 14, 2019 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jechlin/c3c8d167d9c26c00d6828325ff390179 to your computer and use it in GitHub Desktop.
Save jechlin/c3c8d167d9c26c00d6828325ff390179 to your computer and use it in GitHub Desktop.
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
def userManager = ComponentAccessor.userManager
def userService = ComponentAccessor.getComponent(UserService)
[
'anuser',
'otheruser',
// add more as required
].each { username ->
def user = userManager.getUserByName(username)
if (!user) {
log.warn "Failed to find user with name ${username}"
return
}
def updatedUser = userService.newUserBuilder(user).active(false).build()
def updateUserValidationResult = userService.validateUpdateUser(updatedUser)
if (updateUserValidationResult.isValid()) {
log.warn "Deactivating user ${username}"
userService.updateUser(updateUserValidationResult)
} else {
log.warn "Update of ${user.name} failed: ${updateUserValidationResult.errorCollection.errors.entrySet().join(',')}\n"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment