Community moderators have prevented the ability to post new answers.
Here's some sample code... in groovy but you can easily write as java
For JIRA 7:
def userManager = ComponentAccessor.getUserManager() def userService = ComponentAccessor.getComponent(UserService.class) def user = userManager.getUserByName(username) def updateUser = userService.newUserBuilder(user).active(false).build() def updateUserValidationResult = userService.validateUpdateUser(updateUser) if (updateUserValidationResult.isValid()) { userService.updateUser(updateUserValidationResult) } else { log.warn "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}\n" }
in JIRA 6:
def userService = ComponentAccessor.getComponent(UserService.class) def user = userUtil.getUserByName(username).getDirectoryUser() def updateUser = ImmutableUser.newUser(user).active(false).toUser() def updateUserValidationResult = userService.validateUpdateUser(updateUser) if (updateUserValidationResult.isValid()) { userService.updateUser(updateUserValidationResult) } else { log.warn "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}\n" }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie, ImmutableUser is not found in com.atlassian.crowd.embedded.impl package. I am using amps version 5.0.13. Could you please suggest?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what version of jira?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie, Actually I need to implement in JAVA for JIRA version 6.2 but for testing the code I'm using groovy console where it was not working. validateUpdateUser method is deprecated in JAVA so I'm trying for different way to deactivate users. Could you please suggest? userService.validateUpdateUser(updateUser) Thanks, Srinivas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My Java code is running as JIRA service and there is no user with the current JIRA authentication context. I had added the statement to run as specific user with admin rights and now it started working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie Echlin [Adaptavist] can you please help with above code you wrote for JIRA version 6.4.14 and version 7 .
i want to activate users using groovy code but getting error .
how i am trying is pull userid from the custom field and process it in the post function to mark it as active .
Abyakta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've updated my answer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie Echlin [Adaptavist]
I tried the code for jira 6 but faced below error .please help.
groovy.lang.MissingPropertyException: No such property: userUtil for class: Script14 at Script14.run(Script14.groovy:12)
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.