Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

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.
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
TAGS
AUG Leaders

Atlassian Community Events