Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Remove Users from a custom Jira group

Hi,

 

I have written a script for removing 100+ users from a custom Jira group. I have tried to run this in Script console in Jira 6.4.13, but it is giving me an error:

 

Please assist

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.groupManager
def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager

def usersToRemove = ["exampleUser1","exampleUser2","exampleUser3","exampleUser4","exampleUser5"] //User Names
def groupToAlter = groupManager.getGroup("NameOfGroup")

usersToRemove.each{
def currentUser = userManager.getUserByName(it)
userUtil.removeUserFromGroup(groupToAlter, currentUser)
}




 

Error:

 

No signature of method: com.atlassian.jira.user.util.UserUtilImpl.removeUserFromGroup() is applicable for argument types: (com.atlassian.crowd.embedded.impl.ImmutableGroup, com.atlassian.jira.user.DelegatingApplicationUser)

 

 

It is something related to UserUtil class, but not able to figure out a solution for this

 

 

2 answers

1 accepted

1 vote
Answer accepted

Hello,

What is your Jira version?

HI @Alexey Matveev _Appfire_, it is 6.4.13 Jira server

Try like this:

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.groupManager
def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager

def usersToRemove = ["exampleUser1","exampleUser2","exampleUser3","exampleUser4","exampleUser5"] //User Names
def groupToAlter = groupManager.getGroup("NameOfGroup")

usersToRemove.each{
def currentUser = userManager.getUserByName(it)
userUtil.removeUserFromGroup(groupToAlter, currentUser.getDirectoryUser())
}

You are welcome!

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.bc.user.UserService
import com.atlassian.jira.user.ApplicationUser
final List<String> jiraList =[]

def userService = ComponentAccessor.getComponent(UserService)
def asUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
//def userService = ComponentAccessor.getComponent(UserService)
def groupManager = ComponentAccessor.getGroupManager()


groupManager.getUsersInGroup("<group_name>").each {

jiraList.add(it.username)

}

jiraList.each {
def cur = userManager.getUserByName(it)
UserService.DeleteUserValidationResult result = userService.validateDeleteUser(asUser,cur)
if (result.isValid()){
log.warn "delete ${cur}"
userService.removeUser(asUser, result)
} else {
log.warn "Update of ${cur} failed: ${result.errorCollection.errors.entrySet().join(',')}\n"
} }

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you