Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Add/Remove group from space confluence with script runner



i would like to add or remove groups from spaces in confluence with scriptrunner.

do you have a solution?



for Tony Gough [Adaptavist] , i don't see your answer in my browser (only in my email).

3 answers

2 accepted

Hi laumain,

I've written an example script which shows you how to add a group to a space with view permissions on that space.

import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.user.GroupManager
import com.atlassian.confluence.core.ContentPermissionManager

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def spacePermissionManager = ComponentLocator.getComponent(SpacePermissionManager)
def groupManager = ComponentLocator.getComponent(GroupManager)

def targetSpace = spaceManager.getSpace("SPACEKEY")
def targetGroup = groupManager.getGroup("groupname")

//Ensure the space doesn't have the group already
if (!spacePermissionManager.getGroupsWithPermissions(targetSpace).contains(targetGroup)) {
//Add the group to the space with, with view permissions
def spacePermission = SpacePermission.createGroupSpacePermission(SpacePermission.VIEWSPACE_PERMISSION, targetSpace, targetGroup.getName())

The two main constructs involved in this are SpacePermission and SpacePermissionManager. The documentation describes various other methods to achieve additional functionality: 

thanks for your reponse. it's OK :)

do you know how i remove group in permission?

i'm looking for removeGroupSpacePermission , but i don't see that :(

Hi laumain,

To remove a permission, you must load it into a variable, then use the SpacePermissionManager to remove it. The following is an example:

def perms = spacePermissionManager.getAllPermissionsForGroup("groupname")

I hope this helps!

Kind regards,

Hi tony,

thanks a lot,

but where do you specify spaces?

should I understand, all permissions are removed from all spaces?



Hi laumain,

In the example above I selected the first permission from the list of permissions for the group 'groupname'. There are various ways of selecting a specific permission - you could use the getGroupsWithPermissions method to get a list of all groups which have permissions on the space, for example, then use getAllPermissionsForGroup to retrieve the object with the group's permissions. Once you have the object, you can iterate through it to find the permission you wish to remove, then remove it with the removePermission method from the spacePermissionsManager.

Kind regards,

perfect tony , you are a chief!!



Thanks for alerting me to that, not sure why my original comment did not appear. I'll repost a link to the script here:

The important constructs to note are the SpacePermission and SpacePermissionManager from the API:

The documentation describes further methods you can use to achieve different functionality with these.

Kind regards,

Excellent work @Tony Gough _Adaptavist_!

Can you help with the appropriate script just to update the space view permissions using the Confluence groups that the space creator belongs too?

Acceptance Criteria: Once a user creates a Confluence space, all groups that the space creator belongs to will be added to space view permissions, except the "confluence-users" group.

I planning on using scriptrunner's space create event listener to trigger the script that will fetch all Confluence groups of the space creator and add them to space view permissions.

Appreciating your insight!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

Codegeist '21 Customer Choice Awards - Vote Now!

Last quarter, 290 developers participated in Atlassian’s annual hackathon, Codegeist, for a chance to win thousands of dollars with a new Marketplace app. We announced winners selected by Atlassian...

910 views 4 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you