We added users by mistake to the Jira Internal Directory, there are no issues associcated with these userNames. These users already exist in crowd or LDAP, so there is no problem with us deleting these users.
I have a csv file with a list of users(3000)-- csvFile.csv
"user1","user2","user3", "user4", "user5"
I would like to access this csv file read the data from it and delete all the users listed in the file from the jira Internal directory.
I know how to delete these users by adding them to a string in the script but would like help in figuring out how to read the list from the csv file and deleting them using the list of usernames within the file:
How do I get the contents of the contents of the csvFile to the def userNames?
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import org.supercsv.io.CsvBeanReader
import org.supercsv.io.CsvMapReader
import org.supercsv.prefs.CsvPreference
import org.supercsv.cellprocessor.CellProcessorAdaptor
import org.supercsv.cellprocessor.ift.CellProcessor
import org.supercsv.cellprocessor.Optional
def csvFile="/some/path/csvFile.csv"
def userService = ComponentAccessor.getComponent(UserService)
def asUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
//usernames to remove
def userNames =
userNames?.each { it ->
final UserService.DeleteUserValidationResult result = userService.validateDeleteUser(asUser, it)
if (result.isValid()) {
userService.removeUser(asUser, result)
log.info "User with username $it removed"
}
else {
log.error "Failed to remove user with username $it. " + result.getErrorCollection().errorMessages
}
}