I want to remove a group for required spaces by using groovy script

SunadhRaj.Malaka October 25, 2023

Hi Guys ,

I want to remove particular groups for required and specified spaces by providing space key by using Groovy Script.

Example : i have 20 spaces , "Test-A , Test-B" Groups are linked with those 20 spaces , i want to remove the groups "Test-A , Test-B" to all 20 spaces .

I am looking for Groovy script.

So some help or suggest me .

 

Thank You 

Sunadh Raj

1 answer

0 votes
Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 26, 2023

I've adapted one of my scripts that does something similar.

There are a  number of deprecated methods in there, but for now, they still work. So it should do the trick for you.

Define the spaces and groups on line 11 and 12.

Comment out line 20 to run a test first and review the logs to make sure the actions are what you expect.

 

import com.atlassian.confluence.security.SpacePermissionManager
import com.atlassian.confluence.spaces.SpaceManager
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import org.apache.log4j.Level

log.setLevel(Level.INFO)
@PluginModule SpaceManager spaceManager
SpacePermissionManager spacePermissionManager = ScriptRunnerImpl.getPluginComponent(SpacePermissionManager)

def spaceKeys = ['SP1', 'SP2']
def groupsToRemove = ['Test-A', 'Test-B']
spaceKeys.each { spaceKey ->
def space = spaceManager.getSpace(spaceKey as String)
groupsToRemove.each { group ->
def permissions = space.permissions.findAll { it.getGroup() == group }
if (permissions) {
permissions.each {
log.info "Removed $it.type permission from $group group in space $spaceKey"
spacePermissionManager.removePermission(it)
}
} else {
log.warn "No permissions for $group was found in space $space"
}
}
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events