Script runner - Automatically deactivate inactive JIRA users - permission error

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 

 

 


1 answer

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.]

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

243 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you