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
4,298,467
Community Members
 
Community Events
165
Community Groups

Set and remove multiple permissions on a page

Hi there!

I am trying to remove and add permissions (page restrictions) in bulk on Confluence Pages using Scriptrunner. I am looping through my ids which I'm getting from a resultset of a database query.

When iterating through I get this error after the permissions of the first entry are set and removed correctly:

2022-04-27 08:18:12,662 ERROR [common.UserScriptEndpoint]: Script console script failed:

java.util.ConcurrentModificationException at org.hibernate.collection.internal.AbstractPersistentCollection$IteratorProxy.next(AbstractPersistentCollection.java:864) at testLoop.run(testLoop.groovy:50)

this is my script:

def userAccessor = ComponentLocator.getComponent(UserAccessor)
def contentPermissionManager = ComponentLocator.getComponent(ContentPermissionManager)

String[] PageIds = ["31920133", "126354667"
String groupToRemove = "group"

def pageManager = ComponentLocator.getComponent(PageManager)
def pages
def List<Page> pagesPageList = []
pages = PageIds.each{ pagesToEdit ->
    if (!pagesToEdit) {
        log.warn("Page: " + pagesToEdit + " was not found in the System.")
    }
    pagesPageList.add(pageManager.getPage(pagesToEdit.toLong()))
}

   

def group = userAccessor.getGroup(groupToRemove)

if (!group) {
    log.warn("Group: " + groupToRemove + " was not found in the System.")
}

String[] groupsToAdd = ["se", "ssa-test"]

def editPermissions = []
    groupsToAdd.each{ groupToAdd ->
    editPermissions.add(ContentPermission.createGroupPermission(EDIT_PERMISSION, groupToAdd as String))
}

def mapEdit = [(EDIT_PERMISSION): editPermissions] as Map

//EDIT
for (Page page : pagesPageList) {
    for (ContentPermission cp : page.getContentPermissionSet(ContentPermission.EDIT_PERMISSION)) {
        log.warn(cp.toString())
       
        if (cp.toString().contains("groupName=" + groupToRemove)) {
            // Remove the Permission
            log.warn("Group: " + groupToRemove + " was found having EDIT Permissions for Page Id: " + page.getContentId() + ".")
            contentPermissionManager.removeContentPermission(cp);
            log.warn("Removed EDIT permissions for Group: " + groupToRemove + " for Page Id: " + page.getTitle() + ".")
            // Set the Permission
            contentPermissionManager.setContentPermissions(mapEdit, page)
            log.info("Added EDIT Permission for Group: " + mapEdit + " for Page Id: " + page.getTitle() + ".")
            }
    }
}
I assume I have to somehow commit the first operation but I don't know how... 
Hope that someone can help me - thank you in advance!!
Best regards
Sabrina

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

187 views 1 3
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