Hi I want to automatically deactivate inactive JIRA users.
So I do references to the site(https://www.adaptavist.com/doco/display/SFJ/Automatically+deactivate+inactive+JIRA+users)
First Case.
Login Admin User.
go Admin Page > Add-ons > Script Console
write this code
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 = 100 // 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{it.isActive()}.each {
UserWithAttributes user = crowdService.getUserWithAttributes(it.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++
} else {
log.error "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}"
}
}
}
}
"${count} users deactivated.\n"and Run.
it is working well.
Second Case.
Go Admin Page > System > Services
Add Service - Classs(com.onresolve.jira.groovy.GroovyService)
And Source code is jira-home-dir/scripts/xxxx.groovy (this code is same)
But it is not work.
So I search error log.
Source code have not permission in Services. How can i grant authority.?
I looking for your answer.
Thank you
This is error log.
2017-02-08 10:16:59,028 Caesium-1-2 ERROR anonymous Inactive [c.o.scriptrunner.runner.ScriptRunnerImpl] 이경언 = Mon Feb 06 09:45:02 KST 2017
2017-02-08 10:16:59,028 Caesium-1-2 ERROR anonymous Inactive [c.o.scriptrunner.runner.ScriptRunnerImpl] find user
2017-02-08 10:16:59,028 Caesium-1-2 ERROR anonymous Inactive [c.o.scriptrunner.runner.ScriptRunnerImpl] H8055(h8055)
2017-02-08 10:16:59,028 Caesium-1-2 ERROR anonymous Inactive [c.o.scriptrunner.runner.ScriptRunnerImpl] com.atlassian.jira.bc.user.UserService$UpdateUserValidationResult@30e78d1a
2017-02-08 10:16:59,028 Caesium-1-2 ERROR anonymous Inactive [c.o.scriptrunner.runner.ScriptRunnerImpl] false
2017-02-08 10:16:59,028 Caesium-1-2 ERROR anonymous Inactive [c.o.scriptrunner.runner.ScriptRunnerImpl] Errors: {}
Error Messages: [You do not have the permission to update users.]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Please try to use this code (Accept Answer).
I hope that could help you. :)
Many Thanks and Kind Regards,
Jose
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.