Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

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
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 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