Hello. I've written script which finds all inactive users in project roles in all projects
UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class)
//find all inactive users
UserSearchParams userSearchParams = (new UserSearchParams.Builder()).allowEmptyQuery(true).
includeActive(false).includeInactive(true).maxResults(100000).build()
def inactiveUsers = userSearchService.findUsers("", userSearchParams)
//find all projects
def allProjects = ComponentAccessor.getProjectManager().getProjectObjects()
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def projectRoles
inactiveUsers.each {
for (def project : allProjects){
projectRoles = projectRoleManager.getProjectRoles(it, project)
if (projectRoles.size() != 0){
log.info("User's roles ${it.name} in project ${project.key} : ${projectRoles}")
}
}
}
In logs I have User's roles username in project TEST : [Support-users, Users]
But how can I remove this users from project roles?
Hi,
I think you have to use ProjectRoleService
This is my test code... need to be combined with yours but more or less works:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.jira.security.roles.actor.UserRoleActorFactory
import com.atlassian.jira.security.roles.RoleActorFactory
UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class)
ProjectRoleService projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)
RoleActorFactory roleActorFactory = ComponentAccessor.getComponent(RoleActorFactory)
/*
//find all inactive users
UserSearchParams userSearchParams = (new UserSearchParams.Builder()).allowEmptyQuery(true).
includeActive(false).includeInactive(true).maxResults(100000).build()
def inactiveUsers = userSearchService.findUsers("", userSearchParams)
*/
//find all projects
def user = ComponentAccessor.getUserManager().getUserByName("u41958")
//def allProjects = ComponentAccessor.getProjectManager().getProjectObjects()
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("projectkey")
user.getUsername()
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def projectRoles
projectRoles = projectRoleManager.getProjectRoles(user, project).each{
def role = it
def users = [user.getUsername().toString()]
log.error users
SimpleErrorCollection errorCollection = new SimpleErrorCollection();
projectRoleService.removeActorsFromProjectRole(users, role, project, "atlassian-user-role-actor", errorCollection) //atlassian-group-role-actor
}
BR,
Lukasz
In @Łukasz Sielski priv code above.
def users = [user.getUsername().toString()]
may need to be
def users = [user.getKey().toString()]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I want to remove group from project role.
How this is possible with scriptrunner?
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.