I am migrating from Bugzilla to JIRA and while the Bugzilla users come into the system under a group called "bugzilla-import-disabled-users" or "bugzilla-import-unused-users", they are coming in as "active". This is triggering an error for licensing, and with > 2000 disabled/unused users, I don't want to have to edit these all manually. Can anyone point me to how I can do this in bulk?
Thanks!
You can use the Script Runner plugin and the following script:
import com.atlassian.crowd.embedded.api.CrowdService import com.atlassian.crowd.embedded.api.User 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.util.UserUtil String result = '' UserUtil userUtil = ComponentAccessor.userUtil CrowdService crowdService = ComponentAccessor.crowdService UserService userService = ComponentAccessor.getComponent(UserService.class) User updateUser UserWithAttributes user UserService.UpdateUserValidationResult updateUserValidationResult def groupNames = [ 'bugzilla-import-disabled-users', 'bugzilla-import-unused-users' ] userUtil.getAllUsersInGroupNamesUnsorted(groupNames).findAll{it.isActive()}.each { user = crowdService.getUserWithAttributes(it.getName()) updateUser = ImmutableUser.newUser(user).active(false).toUser() updateUserValidationResult = userService.validateUpdateUser(updateUser) if (updateUserValidationResult.isValid()) { userService.updateUser(updateUserValidationResult) result += "Deactivated ${updateUser.name}\r\n" } else { result += "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}\r\n" } } return result
Please test in testsystem first!
Henning
Thanks, Henning. I ended up filing a support request with Atlassian, and it seems that this is not intended behavior of the importer. The script looks like it might be handy if there's not another solution. Thanks for posting it. If i need to, I'll test this out in my staging environment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For example,
This seems to work in script runner, but it doesn't store change.
import com.atlassian.crowd.embedded.api.CrowdService import com.atlassian.crowd.embedded.api.User 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.util.UserUtil String result = '' UserUtil userUtil = ComponentAccessor.userUtil CrowdService crowdService = ComponentAccessor.crowdService UserService userService = ComponentAccessor.getComponent(UserService.class) User updateUser UserWithAttributes user UserService.UpdateUserValidationResult updateUserValidationResult def groupNames = [ 'deactivated-users', ] userUtil.getAllUsersInGroupNamesUnsorted(groupNames).findAll{it.isActive()}.each { user = crowdService.getUserWithAttributes(it.getName()) ApplicationUser appUser= userUtil.getUserByName(it.getName()) updateUser = ImmutableUser.newUser(user).active(false).toUser() updateUserValidationResult = userService.validateUpdateUser(appUser) if (updateUserValidationResult.isValid()) { userService.updateUser(updateUserValidationResult) result += "Deactivated ${updateUser.name}\r\n" } else { result += "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}\r\n" } } return result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Maybe a cache issue? Did you tried to refresh the JIRA cache (using the built-in script)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning,
Still running into problems.
When I run the script, it says the users are deactivated. But even when I refresh the cache, and run it, same problem.
I ran the script and dumped out contents of updateUserValidationResult:
<com.atlassian.crowd.model.user.DelegatingUserWithAttributes@2f56ea4b user=testing-123:10400 user=testing-123:10400 attributes=com.atlassian.crowd.embedded.impl.ImmutableAttributes@3fb46d1f>
<com.atlassian.jira.bc.user.UserService$UpdateUserValidationResult@26537e15 user=testing-123(testing-123) errorCollection=Errors: {}
Error Messages: []>
<com.atlassian.crowd.model.user.DelegatingUserWithAttributes@82a778f5 user=jiratestuser:10400 user=jiratestuser:10400 attributes=com.atlassian.crowd.embedded.impl.ImmutableAttributes@7567e92b>
<com.atlassian.jira.bc.user.UserService$UpdateUserValidationResult@1c2c14f2 user=jiratestuser(jiratestuser) errorCollection=Errors: {}
Error Messages: []>
<com.atlassian.crowd.model.user.DelegatingUserWithAttributes@4bdf84b9 user=jira-test-user:10400 user=jira-test-user:10400 attributes=com.atlassian.crowd.embedded.impl.ImmutableAttributes@22dfddd4>
<com.atlassian.jira.bc.user.UserService$UpdateUserValidationResult@68e775cc user=jira-test-user(jira-test-user) errorCollection=Errors: {}
Error Messages: []>
<com.atlassian.crowd.model.user.DelegatingUserWithAttributes@473545d7 user=bryan-test:10400 user=bryan-test:10400 attributes=com.atlassian.crowd.embedded.impl.ImmutableAttributes@40111438>
<com.atlassian.jira.bc.user.UserService$UpdateUserValidationResult@3f24b87c user=bryan-test(bryan-test) errorCollection=Errors: {}
Error Messages: []>
<com.atlassian.crowd.model.user.DelegatingUserWithAttributes@b13858ff user=tempfix:10400 user=tempfix:10400 attributes=com.atlassian.crowd.embedded.impl.ImmutableAttributes@3f245740>
<com.atlassian.jira.bc.user.UserService$UpdateUserValidationResult@2e91ee6b user=tempfix(tempfix) errorCollection=Errors: {}
Error Messages: []>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning -- the link below has a version of your script that works in Jira 6.2.5.
Since you are the author, thanks! I appreciate all your examples in the forum.
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 errors = '' userManager.getUsers().findAll{user -> user.name == 'test-user'}.each { user -> updateUser = ImmutableUser.newUser(user).active(false).toUser() updateUserValidationResult = userService.validateUpdateUser(updateUser) if (updateUserValidationResult.isValid()) { userService.updateUser(updateUserValidationResult) } else { errors += "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}\n" } } return errors
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the kind words and a working version of the script. It's weird, the deprecated version of validateUpdateUser() using com.atlassian.crowd.embedded.api.User
is working while the one using the ApplicationUser is not... Shortly we will switch to 6.2, maybe this is going to be fun... :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi -- maybe I was having a cache issue originally -- because your script from Aug 13 works for me too without modification.
In any event, thanks again. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wrote a blog post on how to bulk edit Jira user e-mail accounts.
It's based on ScriptRunner and Groovy.
Cheers!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe the best way to disable users would be to simply set their 'active' value to 0 in the database.
Just be sure to have a database backup before doing the changes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You may find the query to perform this change on the related post below:
https://answers.atlassian.com/questions/127643/how-to-deactivate-a-user-programmatically-java-rest-sql
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.