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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,802 views 11 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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot