I am running the below script in Script Console of Script Runner. Do i need to configure or add something to the below Script.
The Script will remove users who have not used JIRA since last 3 months.
import com.atlassian.confluence.security.PermissionManager
import com.atlassian.confluence.security.login.LoginManager
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.user.UserManager
import groovy.time.TimeCategory
def userManager = ComponentLocator.getComponent(UserManager)
def userAccessor = ComponentLocator.getComponent(UserAccessor)
def loginManager = ComponentLocator.getComponent(LoginManager)
def permissionManager = ComponentLocator.getComponent(PermissionManager)
def threeMonthsBack
use(TimeCategory) {
threeMonthsBack = 3.months.ago
}
def users = userManager.users
def page = users.currentPage
while (true) {
page.each { user ->
if (userAccessor.isDeactivated(user)) {
return
}
log.debug(user)
def userLoginInfo = loginManager.getLoginInfo(user)
def lastSuccessfulLoginDate = userLoginInfo?.lastSuccessfulLoginDate
def toDeactivate = ! lastSuccessfulLoginDate || lastSuccessfulLoginDate < threeMonthsBack
if (toDeactivate) {
log.warn "Found user: ${user.name} with last login date ${lastSuccessfulLoginDate}, will deactivate"
return
if (!permissionManager.isSystemAdministrator(user)) {
log.info "Deactivating user.."
userAccessor.deactivateUser(user)
}
}
}
if (users.onLastPage()) {
return
}
else {
users.nextPage()
}
}
I receive the below error.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 4: unable to resolve class com.atlassian.sal.api.component.ComponentLocator
@ line 4, column 1.
import com.atlassian.sal.api.component.ComponentLocator
^
Script1.groovy: 2: unable to resolve class com.atlassian.confluence.security.login.LoginManager
@ line 2, column 1.
import com.atlassian.confluence.security.login.LoginManager
^
Script1.groovy: 1: unable to resolve class com.atlassian.confluence.security.PermissionManager
@ line 1, column 1.
import com.atlassian.confluence.security.PermissionManager
^
Script1.groovy: 5: unable to resolve class com.atlassian.user.UserManager
@ line 5, column 1.
import com.atlassian.user.UserManager
^
Script1.groovy: 3: unable to resolve class com.atlassian.confluence.user.UserAccessor
@ line 3, column 1.
import com.atlassian.confluence.user.UserAccessor
^
5 errors
at com.adaptavist.sr.cloud.workflow.AbstractScript.parseScript(AbstractScript.groovy:51)
at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:32)
at com.adaptavist.sr.cloud.workflow.AbstractScript$evaluate$0.callCurrent(Unknown Source)
at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:27)
at ConsoleScriptExecution1_groovyProxy.run(Unknown Source)
Can anyone please help me out to fix this
@Mark Markov - I tried the script in the link you provided but its the same issue.
1. How do i resolve the warnings i receive on the Script Console.
2. I receive the same error message when i try to run the script as Current user.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.