Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bulk change username to email

Kade Price
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 5, 2017

We've imported our old mantis project. The users came along with it, but the user names are very random. I want to change all of them to the users email, so they can just come to the portal and do a password reset to get their account up and going again. 

I have script runner, and I've seen a few scripts, but I'm not having much luck with it. I have a dev server setup where I can test my scripts. I don't know Java and I'm kind of lost as to what I want to do.

The users have the mantis-import-unused-users group assigned to them so I can use that to select them. 

I want to then loop though them and change the username to their email address.

 

Thanks in advanced. 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Gaston Valente
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 5, 2017

Kade,

Do you have some code for what you need to do to start with?

Are you using internal directory or some kind of ldap?

thanks!

Kade Price
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 6, 2017

The users are internal. Employees use LDAP. So I can't mess with that. 

 

This looked promissing and a good start, but it doesn't seem to be quite compatable with my version of JIRA.

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 = [
        'mantis-import-disabled-users',
        'mantis-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
TAGS
AUG Leaders

Atlassian Community Events