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
Hi @Fabio Oliveira Silva
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.CrowdServiceimport com.atlassian.crowd.embedded.api.UserWithAttributesimport com.atlassian.crowd.embedded.impl.ImmutableUserimport com.atlassian.jira.bc.user.UserServiceimport com.atlassian.jira.bc.user.search.UserSearchParamsimport com.atlassian.jira.bc.user.search.UserSearchServiceimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.security.groups.GroupManagerimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.jira.user.ApplicationUsersimport com.atlassian.jira.user.util.UserUtilint numOfDays = 300 // Number of days the user was not logged inDate dateLimit = (new Date())- numOfDaysUserUtil userUtil = ComponentAccessor.userUtilCrowdService crowdService = ComponentAccessor.crowdServiceUserService userService = ComponentAccessor.getComponent(UserService)UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class);UserSearchParams userSearchParams = new UserSearchParams(true, true, false);List<ApplicationUser> userList = userSearchService.findUsers("", userSearchParams);ApplicationUser updateUserUserService.UpdateUserValidationResult updateUserValidationResultlong count = 0GroupManager 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"
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
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 clickFeel free to reach out to us at atlassiansupport@xecurify.com or you can raise the ticket in case you need any help!
Thanks,
Mahima
Hello @Mahima_miniOrange
Thank you for your answer, yes we will use this plugin in the near future
I jut puted an else after if (lastLoginMillis?.isNumber()) to get all the never active users, it works, thank you very much
It looks like you're new here. Sign in or register to get started.