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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,433
Community Members
 
Community Events
176
Community Groups

Get all user groups except confluence user group for space view permission?

Edited

My goal in Confluence is to add all user groups that the user belongs to except any group that contains or begins with "confluence", to the space view permission during space creation.

I have found this script in our community (@Tony Gough _Adaptavist) that I would like to leverage in scriptrunner's space create event listener.

I'm unfamiliar on how to call out for the users permissions (except confluence group) instead of using the one provided in the script below.

import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.security.SpacePermissionManager
import com.atlassian.confluence.security.SpacePermission
import com.atlassian.user.GroupManager
import com.atlassian.confluence.core.ContentPermissionManager
import com.atlassian.confluence.internal.security.SpacePermissionContext

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())
spacePermissionManager.savePermission(spacePermission)
}

 Thanks!

1 answer

Adaptavist (@HelmyIbrahim) was able to help me out and after using their approach, we now have this working:

import com.atlassian.user.GroupManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal
import com.atlassian.confluence.security.SpacePermissionManager
import com.atlassian.confluence.security.SpacePermission

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

def targetSpace = event.getSpace()
def loggedInUser = AuthenticatedUserThreadLocal.get()

// Get all groups for loggedInUser and exclude group that contains 'confluence'def groups = groupManager.getGroups(loggedInUser).currentPage.findAll { !it.name.contains('confluence') }

groups.each { group -> 
    def spacePermission = SpacePermission.createGroupSpacePermission(SpacePermission.VIEWSPACE_PERMISSION, targetSpace, group.getName())
    spacePermissionManager.savePermission(spacePermission)
}

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events