Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Add group-permissions for each page in a space

Hello community, I want to bulk add a group-permission to all pages in a space. I already came up with a script, but it does not work as expected yet. 

  • When I run this script for a complete space (with about 300 pages), the script does nothing, it does not even show any output at all, also no error message. 
  • When I run this script for e.g. only one page (restricted via a simple if-statement in the for loop) the permission is successfully set. 
  • When I run this script for the first 3 pages (also restricted via a simple if statement and a counter) the permission is set for the last page of the iteration. Strangely the first two pages do not get the group-permission added. 

Here is my current (simplified) implementation. 

import com.atlassian.confluence.labels.Label
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.api.service.content.SpaceService
import com.atlassian.confluence.core.ContentPermissionManager
import com.atlassian.user.GroupManager
import static

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)
def spaceService = ComponentLocator.getComponent(SpaceService)
def contentPermissionManager =ComponentLocator.getComponent(ContentPermissionManager)

Space sourceSpace = spaceManager.getSpace("TEST")

def groupPermission = ContentPermission.createGroupPermission(EDIT_PERMISSION, "editor-group")

for (Page page : pageManager.getPages(sourceSpace, true)) {
  def currentPage = page
  contentPermissionManager.addContentPermission(groupPermission, currentPage)

What is wrong here? Do I miss something along the lines of a commit/save for each and every page? 

Thanks, Christoph

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

Marketplace Partner Spotlight: AppLiger

This month the spotlight is on AppLiger. We caught up with Pavel Pavlovsky, CEO and Product Manager, to learn how the company started and what fuels the team's creativity.    Atlassian:...

396 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you