Overview

There are two types of permissions at the Space level in Confluence: Space permissions, and Page permissions.

Page permissions are much simpler than Space permissions, for the simple reason that there are only TWO types of Page permission: VIEW and EDIT.

Getting Permissions From a Page

Simply retrieving the permissions of a Page is pretty simple. As you can see in the code below, you need only fill in a view variables: the page ID, and the type of Permission you’d like review.

import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.security.ContentPermission
import com.atlassian.confluence.user.UserAccessor


def userAccessor = ComponentLocator.getComponent(UserAccessor)
def pageManager = ComponentLocator.getComponent(PageManager)
//Define the user accessor and the page manager

def currentPage = pageManager.getPage(83591282)
//Use the page manager to get a specific page

def editPermissions = currentPage.getContentPermissionSet(ContentPermission.VIEW_PERMISSION)
//Define the type of permissions to be returned

editPermissions.getUserKeys().each{names -> 
//For each person with the type of permissions
    
      log.warn(userAccessor.getUserByKey(names).getName())
    //Take the user key and user it to fetch the name of the associated user
}

 

The page ID of any Confluence page is available under Page Information, under the ellipses in the top-right corner:

In this case the Page ID is 83591282.  The other piece of information that the script needs is the type of permission to return. This is simply a matter of changing ContentPermission.VIEW_PERMISSION to reflect the desired permission, such as VIEW.

Returning Users

There is a method that directly returns the usernames from the userAccessor, but that method has been deprecated and Atlassian has not replaced it.   Instead we must get the userKey of each person with the target permission type, and use that userKey to get the user’s name.

Worth noting is that there are two lists of permissions, when it comes to who can View a page.   Under the same ellipses where you found the Page ID, there is a list of people who can view the page:

This is not the same as having VIEW permissions on the page. Instead these are users with global permissions in Confluence, likely Systems Administrators.    These users will not be returned when you query a page for the persons having VIEW permissions.

Indeed, no users will be returned if you query a page that has been set to allow anyone to view.    Only pages with View Restrictions will return a list of users with VIEW permissions:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>