Hi
I need to make a scriptRunner to desactivate users that have never logged, I'm using Jira 7
Have you any idea please?
Thank you
Hello @Firas hammami there is another topic here with detailed information about this task, please take a look and let me know if you need any other information:
https://community.atlassian.com/t5/Adaptavist-questions/Scriptrunner-deactivate-inactive-users-script-needs-to-be/qaq-p/914110
thank you for your answer, this script can desactivate all users that have been inactive for a certain period, I dit something like this ans it works, but my problem is to desactivate users that have never logged in
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.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.user.util.UserUtil
int numOfDays = 300 // 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)
UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class);
UserSearchParams userSearchParams = new UserSearchParams(true, true, false);
List<ApplicationUser> userList = userSearchService.findUsers("", userSearchParams);
ApplicationUser updateUser
UserService.UpdateUserValidationResult updateUserValidationResult
long count = 0
GroupManager groupManager = ComponentAccessor.getGroupManager();
userList.findAll{it.isActive()}.each {
if(groupManager.isUserInGroup(it.getName(),"jira-administrators"))
return;
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Firas hammami in this case, the never logged-in users should be the ones that have an empty lastLoginMillis information so an else block on the if (lastLoginMillis?.isNumber()) should work, but the problem is that you can deactivate users recently created. I tried to found a way to check created date for a user without success, maybe you can create a user list directly from the database and export it as CSV
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I jut puted an else after if (lastLoginMillis?.isNumber()) to get all the never active users, it works, thank you very much
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Firas hammami ,
This is Mahima from miniOrange.
If you are looking for plugin which can fulfill your requirements, I would like to suggest you User Management Plugin which can automatically deactivate the users who have never logged in or who have not been active since long time which can help you to manage your users easily in just one click
Feel free to reach out to us at atlassiansupport@xecurify.com or you can raise the ticket in case you need any help!
Thanks,
Mahima
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Mahima_miniOrange_SSO
Thank you for your answer, yes we will use this plugin in the near future
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.