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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Posted 7 hours ago in Jira

We want to know what Jira Service Desk apps you're using!

Hi Community! My name is Amir and I’m on the Jira Service Desk product marketing team at Atlassian. Our team would love to understand how you’re leveraging our ecosystem for Jira Service Desk. Wha...

25 views 0 5
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