Is there any method available for marking Users as inactive using Jelly , Groovy or any other script ?
Thanks in advance
Regards,
Sumit
Community moderators have prevented the ability to post new answers.
Using Script Runner you can use this script to deactivate a user:
import com.atlassian.crowd.embedded.api.User 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.util.UserManager UserManager userManager = ComponentAccessor.getUserManager() UserService userService = ComponentAccessor.getComponent(UserService.class) User updateUser UserService.UpdateUserValidationResult updateUserValidationResult userManager.getUsers().findAll{user -> user.displayName == 'Test'}.each { user -> updateUser = ImmutableUser.newUser(user).active(false).toUser() updateUserValidationResult = userService.validateUpdateUser(updateUser) if (updateUserValidationResult.isValid()) { userService.updateUser(updateUserValidationResult) } else { // throw error } }
In this case the script searches for a user with display name "Test" and deactivates this user. You can adapt this to your needs.
Thanks a lot ... you saved my lot of time..!!
You are the BOSS ..!!
Regards,
Sumit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Henning, We are using JIRA 6.2, since validateUpdateUser(User) is deprecated in the latest version, I have modified the JAVA code as below but it is not working. Strangely, the same code is working on groovy console. Am I doing something wrong here? Please suggest. UserService userService = ComponentAccessor.getComponent(UserService.class); UserService.UpdateUserValidationResult updateUserValidationResult; ImmutableUser.Builder builder = ImmutableUser.newUser(jiraUser); builder.active(false); ApplicationUser updatedUser = new DelegatingApplicationUser( jiraUser.getName(), builder.toUser()); updateUserValidationResult = userService.validateUpdateUser(updatedUser); if (updateUserValidationResult.isValid()) { userService.updateUser(updateUserValidationResult); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you get any errors?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There are no errors. I found updateUserValidationResult.isValid() is returning false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then take a look into the errorcollection of the validation result. In Groovy this could be done like this updateUserValidationResult.errorCollection.errorMessages.each { log?.error "Error Message: $it" } updateUserValidationResult.errorCollection.errors.each { log?.error "Error: $it" } updateUserValidationResult.errorCollection.reasons.each { log?.error "Reason: $it" }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I found there are no error messagas when I execute from groovy console but from JAVA i am seeing this message "You do not have the permission to update users."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If your Java code is running as a service there is probably no user within the current jira authentication context (ComponentAccessor.getJiraAuthenticationContext().getUser()). Try to run as a specific user by setting it to a user who has the needed rights (in this case 'admin', replace with appropriate username)
def user = userManager.getUserByName('admin')
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(user)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, My Java code is running as JIRA service and there is no user with the current JIRA authentication context. With your suggestion, I had added the statement to run as specific user with admin rights and now it started working. Thank you very much for your help, appreciate that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning,
can you help me to make you script work with a condition on a group ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure. Basically you could add your condition to the
.findAll{user -> user.displayName == 'Test'}
part of the script. But more likely you could only retrieve users that are relevant for the groups you're looking for. For this you could use
ComponentAccessor.getUserUtil().getAllUsersInGroupNamesUnsorted(['groupname1', 'groupname2'])
instead of
userManager.getUsers().findAll{user -> user.displayName == 'Test'}
If you need more help, you need to be more specific about your goal.
Have fun,
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning,
it worked perfectly, all my users in "jira-inactive-users" are now disabled. Its great.
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am faceing "Error Messages: [You do not have the permission to update users.]" this issue in service context.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See comment with "running as a service" above (https://community.atlassian.com/t5/Answers-Developer-Questions/marking-bulk-users-as-Active-Inactive-using-groovy-jelly-or-any/qaq-p/547231#M84894).
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.
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.