You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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!
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) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.