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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

733 views 3 11
Read article

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