/*** 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.*/importcom.atlassian.confluence.spaces.SpaceManagerimportcom.atlassian.sal.api.component.ComponentLocatorimportcom.atlassian.confluence.security.SpacePermissionManagerimportcom.atlassian.confluence.security.SpacePermissionimportcom.atlassian.user.GroupManagerdefspaceManager=ComponentLocator.getComponent(SpaceManager)defspacePermissionManager=ComponentLocator.getComponent(SpacePermissionManager)defgroupManager=ComponentLocator.getComponent(GroupManager)deftargetSpace=spaceManager.getSpace("TSPAC")//Space keydeftargetGroup=groupManager.getGroup("newgroup")//Group name//Ensure the space doesn't have the group alreadyif(!spacePermissionManager.getGroupsWithPermissions(targetSpace).contains(targetGroup)){//Add the group to the space with, with view permissionsdefspacePermission=SpacePermission.createGroupSpacePermission(SpacePermission.VIEWSPACE_PERMISSION,targetSpace,targetGroup.getName())spacePermissionManager.savePermission(spacePermission)}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.