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
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"
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.