/**
* A script that should be run in the Script Console of ScriptRunner for Confluence.
* This script adds a group to a Confluence space if the group does not already have permissions there.
*/
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("TSPAC") //Space key
def targetGroup = groupManager.getGroup("newgroup") //Group name
//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)
}
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.