Snippets

Adaptavist Add group to Confluence space

Updated by Tony Gough

File addGroupToConfluenceSpace.groovy Added

  • Ignore whitespace
  • Hide word diff
+/**
+* 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
+
+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)
+}

File snippet.txt Deleted

  • Ignore whitespace
  • Hide word diff
-/**
-* 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
-
-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)
-}
Updated by Tony Gough

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
 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)
Created by Tony Gough

File snippet.txt Added

  • Ignore whitespace
  • Hide word diff
+/**
+* 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)
+}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.