Hello,
I have written a groovy script to deactivate users. The issue I am running into is that the script will fail if the user is a component lead. What I want to do is check if the user is a component lead and remove them if they are. So far I have been struggling to do so. Any help would be much appreciated.
Script to deactivate user:
def deActivateUser(user, email, fullName, userService, userUtil){
deActivate = ImmutableUser.newUser(user).active(false).emailAddress("DELETE.${email}").displayName("${fullName} - OLD").toUser()
//user project or component lead?
def userProjectLead = userUtil.getProjectsLeadBy(user)
def userComponentLead = ComponentAccessor.projectComponentManager.findComponentsByLead("userName")
//get the request
updateUserValidationResult = userService.validateUpdateUser(deActivate)
if (!userProjectLead && !userComponentLead) {
userService.updateUser(updateUserValidationResult)
userUtil.removeUserFromGroup(group, user)
return "User ${user} deactivated"
}