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 

 

 


2 answers

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

 

Hi,

Have you solved the problem?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

27,124 views 2 7
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