Created
October 14, 2019 13:14
-
-
Save jechlin/c3c8d167d9c26c00d6828325ff390179 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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