Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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.