For user management we need a list of all users within the 'Jita Internal Directory' only.
I have a working script, but would prefer to apply a filter when obtaining the users instead of afterwards.
import com.atlassian.jira.bc.JiraServiceContextImpl
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.user.ApplicationUser
UserSearchParams.Builder paramBuilder = UserSearchParams.builder()
.allowEmptyQuery(true)
.includeActive(true)
.includeInactive(true)
.limitResults(20000)
ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
JiraServiceContextImpl jiraServiceContext = new JiraServiceContextImpl(loggedInUser)
Collection<ApplicationUser> users = ComponentAccessor.getComponent(UserSearchService).findUsers(jiraServiceContext, "", paramBuilder.build())
log.info(users.size())
Collection<ApplicationUser> externalUsers = []
for (user in users) {
if (user.directoryId == 1) {
externalUsers.add(user)
}
}
log.info(externalUsers.size())
2023-09-15 09:38:31,851 INFO [runner.ScriptBindingsManager]: 11318
2023-09-15 09:38:31,851 INFO [runner.ScriptBindingsManager]: 10249
Thanks to @Ram Kumar Aravindakshan _Adaptavist_
My updated script now no longer needs to iterate through each user to filter out the non-Internal Directory users, and the directory name can be used as a bonus.
Will just need to monitor the value for limit results.
import com.atlassian.crowd.manager.directory.DirectoryManager
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor
final directoryToCheck = 'Jira Internal Directory'
def directoryManager = ComponentAccessor.getComponent(DirectoryManager)
def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def internalDirectoryId = directoryManager.findAllDirectories()?.find { it.name.toString().toLowerCase() == directoryToCheck.toLowerCase() }?.id
UserSearchParams.Builder paramBuilder = UserSearchParams.builder()
.allowEmptyQuery(true)
.includeActive(true)
.includeInactive(true)
.limitResults(20000)
def allInternalDirectoryUsers = userSearchService.findUsers('', paramBuilder.build()).findAll { it.directoryId == internalDirectoryId }
log.info("Users in Jira Internal Directory: ${allInternalDirectoryUsers?.size()}")
For your requirement, I suggest looking at this Adaptavist Library script.
You will need to modify it slightly as it looks specifically at inactive users.
I hope this helps answer your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ram Kumar Aravindakshan _Adaptavist_ Thank you for the pointer ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.