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 vote
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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

100 views 0 1
Join discussion

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