Bulk change username to email

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

0 votes
Gaston Valente Community Champion Sep 05, 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!

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

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

240 views 0 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot