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

This widget could not be displayed.

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}")

This widget could not be displayed.

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
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

128 views 1 3
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