Bulk edit usernames that are emails
Asked by Joe Ben Clark:

Is it possible to bulk edit usernames that email addresses to eliminate @emailaddress? this is to ensure GDPR compliance


Answers:
author: Bruno Vincent
body: Hi [@Joe Ben Clark](/t5/user/viewprofilepage/user-id/583501)

Yes, a simple script using the [rename](https://docs.atlassian.com/atlassian-crowd/3.2.3/REST/#usermanagement/1/user-renameUser) method of Crowd REST API will do. For instance in Groovy:

```
import groovy.json.JsonSlurper
import groovy.json.JsonOutput

CROWD_SERVER_URL = "http://localhost:8095/crowd"
APPLICATION_NAME = "test"
APPLICATION_PASSWORD = "password"

boolean isEmailAddress(String s){
 emailPattern = /[_A-Za-z0-9-]+(.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(.[A-Za-z0-9]+)*(.[A-Za-z]{2,})/
 return s ==~ emailPattern
}

def removeEmailDomainFromUsername(String username){
 def url = "${CROWD_SERVER_URL}/rest/usermanagement/1/user/rename?username=${URLEncoder.encode(username)}"
 def body = JsonOutput.toJson(["new-name":username.substring(0,username.indexOf('@'))]).getBytes('UTF-8')
 def connection = new URL(url).openConnection()
 connection.setRequestProperty('Authorization', "Basic ${(APPLICATION_NAME + ':' + APPLICATION_PASSWORD).bytes.encodeBase64().toString()}")
 connection.setRequestProperty('Content-Type', 'application/json')
 connection.setRequestProperty('Accept', 'application/json')
 connection.setRequestMethod('POST')
 connection.setDoOutput(true)
 connection.getOutputStream().write(body)
 if (connection.responseCode.equals(200)){
 return true
 } else return false
}

def searchAllUsers(){
 def url = "${CROWD_SERVER_URL}/rest/usermanagement/1/search?entity-type=user"
 def connection = new URL(url).openConnection()
 connection.setRequestProperty('Authorization', "Basic ${(APPLICATION_NAME + ':' + APPLICATION_PASSWORD).bytes.encodeBase64().toString()}")
 connection.setRequestProperty('Accept', 'application/json')
 connection.setRequestMethod('GET')
 if (connection.responseCode.equals(200)){
 def json = connection.inputStream.withCloseable { inStream ->
 new JsonSlurper().parse( inStream as InputStream ) 
 }
 return json.users.name
 } else return []
}

searchAllUsers().each{ username ->
 if (isEmailAddress(username)){
 println "${username} is an email address. Trying to remove the domain extension..."
 if (removeEmailDomainFromUsername(username)){
 println "Success!"
 } else{
 println "Failed to remove domain extension"
 }
 } else{
 println "${username}: nothing to do here"
 }
}
```

![Untitled.png](https://community.atlassian.com/t5/image/serverpage/image-id/27246iECDB97C4CCAFE47A/image-size/large?v=v2&px=999 "Untitled.png")

![Screen Shot 2018-07-18 at 18.38.00.png](https://community.atlassian.com/t5/image/serverpage/image-id/27245i08BB62F1AD049082/image-size/large?v=v2&px=999 "Screen Shot 2018-07-18 at 18.38.00.png")

![Untitled2.png](https://community.atlassian.com/t5/image/serverpage/image-id/27247i693ED9ADE83A3428/image-size/large?v=v2&px=999 "Untitled2.png")Hope this helps!

Bruno

comments: author: Craig Castle-Mead
body: Hi joe,

Out of interest, wondering how removing the domain from the username helps with GDPR compliance when the username is still it's own field?

Given a persons name is still PII, my understanding is that all this info would still need to comply with GDPR requirements.

thanks!

CCM


author: Joe Ben Clark
body: We use crowd for Confluence and JIRA in a public setting. In JIRA, Usernames are exposed when tagging individuals in comments. To avoid this, we intend to convert email based usernames.


author: Craig Castle-Mead
body: Ah rightio - makes sense!

CCM


author: Athena D
body: Awesome! But I would also like to recommend this one <https://gmailbulkemail.com/gmail-bulk-email/> if you want cheap \& easy version that enables the user to send mass email without complications.


Tags: atlassian-support

crowd-administration