Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,294,016
Community Members
 
Community Events
165
Community Groups

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

 

 

3 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!

Hi @Alexey Matveev _Appfire_ 

I would like knwo if i can insert the login  in the "@ShortTextInput"

barre.png

and he display me the groups attached to this user and i can the delete this user for all groups he attached

Example 

Login : test12

 

test12 attchdes groups : group1-user ; group2-dveelopers 

Delete the users test 12  so that it us not part of the groups that are displayed

 

i have started the script but i'm blocked 

script_delete.png

 

Thanks in advance

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