Please help to create Jelly Scrit to remove the user from a Jira group

Hello,

I am using Jira3.13, please help me to remove the bulk user from a particular group.

I have created the following jelly script, which is running without error however group is not removed from the profile.

<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.JiraTagLib">
<jira:RemoveUserFromGroup
name="argulwaa" groupname = "FO (FX)"/>
</JiraJelly>

Thanks in adavcne!

Regards,

Arpita Argulwar

2 answers

You can use following groovy script which checks and disable users and then removes a user from all groups .. you can customize it according to your requirements:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.security.GlobalPermissionManager
import com.atlassian.jira.security.Permissions
import com.atlassian.jira.security.roles.actor.UserRoleActorFactory
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.util.SimpleErrorCollection
import org.apache.log4j.Category
import com.atlassian.jira.project.Project
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.crowd.embedded.api.Group
import org.apache.log4j.Level
import org.apache.log4j.Logger

// Configurable section
isPreview = false
// End
Logger log = Logger.getLogger("********* User **********");
log.setLevel(Level.DEBUG)

// Separating Log from other

log.debug("##########################################################".toString())
log.debug("##########################################################".toString())
log.debug("##########################################################".toString())


userManager = ComponentManager.getInstance().getComponentInstanceOfType(UserManager.class)
GlobalPermissionManager globalPermissionManager = (GlobalPermissionManager) ComponentManager.getInstance().getComponentInstanceOfType(GlobalPermissionManager.class)

def deactivateUser (User user) {

log.debug ("deactivateUser ${user.getName()}")

// Remove user from all groups...
UserUtil userUtil = ComponentManager.getInstance().getUserUtil()
userManager.getGroups().each {
Group group = userManager.getGroupObject(it.getName())
log.debug ("Remove ${user} from group: ${group}")
if (! isPreview) {
userUtil.removeUserFromGroup (group, user)
}
}
// Remove user from all roles...
ProjectRoleService projectRoleService = (ProjectRoleService) ComponentManager.getComponentInstanceOfType(ProjectRoleService.class);
SimpleErrorCollection errorCollection = new SimpleErrorCollection();
log.debug ("Removing all roles references for ${user.getName()}")
projectRoleService.getProjectsContainingRoleActorByNameAndType(userManager.getUser("admin"), user.getName(), UserRoleActorFactory.TYPE, errorCollection).each {Project project ->
log.debug ("Remove user ${user.getName()} from role: ${project.getName()}")
}
if (! isPreview) {
projectRoleService.removeAllRoleActorsByNameAndType (userManager.getUser("admin"), user.getName(), UserRoleActorFactory.TYPE, errorCollection)
}


}
Integer i=0
userManager.getUsers().each {it->

name=it.getDisplayName()
//log.debug ("username ::: ${user}")
//log.debug ("name ::: ${name}")
if (!it.isActive()) {
log.debug ("User: ${it} should be retired")
deactivateUser (it)
i++
}

}
log.debug ("Total ${i}")

there is no jelly tag which can remove users from group ... rather you can remove user completely using jelly.

refer jelly tags at https://confluence.atlassian.com/display/JIRA/Jelly+Tags

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,104 views 13 19
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot