import com.atlassian.crowd.embedded.api.CrowdService
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.ApplicationUser
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.user.util.UserUtil
int numOfDays = 90 // Number of days the user was not logged in
Date dateLimit = (new Date())- numOfDays
UserUtil userUtil = ComponentAccessor.userUtil
CrowdService crowdService = ComponentAccessor.crowdService
UserService userService = ComponentAccessor.getComponent(UserService)
ApplicationUser updateUser
UserService.UpdateUserValidationResult updateUserValidationResult
long count = 0
userUtil.getUsers().findAll{user.isActive()}.each {
UserWithAttributes user = crowdService.getUserWithAttributes(user.getName())
String lastLoginMillis = user.getValue('login.lastLoginMillis')
if (lastLoginMillis?.isNumber()) {
Date d = new Date(Long.parseLong(lastLoginMillis))
if (d.before(dateLimit)) {
updateUser = ApplicationUsers.from(ImmutableUser.newUser(user).active(false).toUser())
updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid()) {
userService.updateUser(updateUserValidationResult)
log.info "Deactivated ${updateUser.name}"
count++
log.error "Update of ${count} ${user.name} success:"
} else {
//log.error "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}"
//"${count} ${updateUser.name} not deactivated.\n"
}
}
}
}
"${count} users deactivated.\n"
this script was working fine for us but since the last time we have an error
error: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.user.util.UserUtilImpl.getUsers() is applicable for argument types: () values: [] Possible solutions: getClass(), every() at Script48.run(Script48.groovy:21)
anybody with strong scripting ,can i get help on this as to what is the error signifying.
Hi @Tim Perrault we are on version 9.4.4 LTS can you let me know what has to be added or removed from the script
Put the script into the script console and it will tell you the issues within your script. With that said, I wouldn't waste time trying to reinvent the wheel. The adaptavist script is exactly what you are trying to do using the latest methods provided.
Literally the only change you would need to make to adaptavist's script is changing def numOfDays = 100 to def numOfDays = 90
@Tim Perrault i see an error when i run the query
error: 2023-07-21 14:08:56,051 ERROR [runner.ScriptBindingsManager]: Update of mczerpak failed. Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2023-07-21 14:08:56,051 ERROR [runner.ScriptBindingsManager]: Update of mdc failed. Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2023-07-21 14:08:56,051 ERROR [runner.ScriptBindingsManager]: Update of mdelafuenter failed. Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2023-07-21 14:08:56,051 ERROR [runner.ScriptBindingsManager]: Update of mdg failed. Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2023-07-21 14:08:56,051 ERROR [runner.ScriptBindingsManager]: Update of mdiaz failed. Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2023-07-21 14:08:56,051 ERROR [runner.ScriptBindingsManager]: Update of mdonohoe failed. Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2023-07-21 14:08:56,051 ERROR [runner.ScriptBindingsManager]: Update of mdougherty failed. Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.] 2023-07-21 14:08:56,051 ERROR [runner.ScriptBindingsManager]: Update of meers failed. Errors: {} Error Messages: [Cannot edit user, as the user's directory is read only.]
The error indicates that the user's directory is read only, meaning you can only read information from the directory and you won't be able to edit the account.
You could go through the Troubleshooting LDAP User Management page to try and determine what is going on.
I would specifically look at this section:
Unable to add/delete Users or make changes to their Groups, Project Roles or Edit them. | The LDAP/AD User Directory is set to Read Only. | Verify the Permissions Settings are correct for the external User Directory. If you want to make changes, Read/Write will need to be activated. If using Active Directory, please refer to this page on Configuring an SSL Certificate. |
@Tim Perrault the script you justed worked fine in test in in production i don see any result
nor any error