Reporting user group usage for page level restrictions?
Asked by ITops123:

We have a lot of defunct user groups in our Confluence instance and it's time to do some spring cleaning.

I know that some of the user groups are being used to set page-level restrictions. But we have about 15,000 pages in our Confluence instance and I need an efficient way to determine which user groups are currently being used to set page-level restrictions, and what those pages are. Otherwise, I run the risk of opening up a sensitive page because I removed the user group.

**Question:** How can I create a report (either the reporting plugin or a SQL query) to answer my question?


Answers:
author: Remo Siegwart
body: As far as I know, it is not possible to query permission with the reporting plugin. In your case I would create a user macro. The following code would loop through all spaces and list all pages with page level restrictions set to a group:

```
## @noparams#set ( $containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager') )#set ( $getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null) )#set ( $containerManager = $getInstanceMethod.invoke(null,null) )#set ( $pageManager = $containerManager.containerContext.getComponent('pageManager') )All pages with page level restrictions set to a group:#set( $allSpaces = $spaceManager.getAllSpaces() )#foreach($space in $allSpaces)&lt;h3&gt;$space.name&lt;/h3&gt;  &lt;table class="confluenceTable"&gt;    &lt;tr&gt;      &lt;th class="confluenceTh"&gt;Page&lt;/th&gt;      &lt;th class="confluenceTh"&gt;Group Permission&lt;/th&gt;    &lt;/tr&gt;    #set( $allPagesInSpace = $pageManager.getPages($space, true) )    #foreach($page in $allPagesInSpace)      #if($page.hasContentPermissions())        #set( $permissions = $page.getPermissions() )        &lt;tr&gt;          &lt;td class="confluenceTd"&gt;#contentLink2($page false false)&lt;/td&gt;          &lt;td class="confluenceTd"&gt;            &lt;ul&gt;              #foreach($permission in $permissions)                #if($permission.isGroupPermission())                  &lt;li&gt;&lt;em&gt;$permission.type&lt;/em&gt; to &lt;strong&gt;$permission.groupName&lt;/strong&gt;&lt;/li&gt;                #end              #end            &lt;/ul&gt;          &lt;/td&gt;        &lt;/tr&gt;      #end    #end  &lt;/table&gt;#end
```

Not sure how this report performs with 15'000 pages, but hope this helps.

comments: author: ITops123
body: Both very helpful, thank you. I'll see if we can run this during a maintenance window and will report back.


author: ITops123
body: UPDATE: This worked really well and performed better than expected. Thanks!


author: Sandro Herrmann [Communardo]
body: To find the pages with group pagerestrictions you can write a user macro. This macro should iterate over all spaces and there pages. If there are page group restrictions at a page an output will be generated. I have prepared this for you.

But WARNING, this usermacro isn't the fastest one and will definitely slow down you system because it iterates over all pages in your big confluence instance. Use this macro only for this usecase and not as a public macro.

```
## @noparams ## DO NOT USE THIS MACRO ON A LOT OF PAGES BECAUSE OF PERFORMANCE ISSUES. IT DEFINITELY WILL SLOW DOWN YOU SYSTEM!!!!! #set($containerManagerClass=$action.class.forName('com.atlassian.spring.container.ContainerManager'))#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))#set($containerManager=$getInstanceMethod.invoke(null,null))#set($containerContext=$containerManager.containerContext)   ## the pageManager gives you access to the pages#set($pageManager =$containerContext.getComponent('pageManager'))  ## the spaceManager gives you access to the spaces#set($spaceManager =$containerContext.getComponent('spaceManager')) ## the contentPermissionManager gives you access to the page permissions#set($contentPermissionManager=$containerContext.getComponent('contentPermissionManager'))   ##over all spaces (WARNING THIS COULD TAKE SOME TIME ON BIG CF INSTANCES )#foreach( $space in $spaceManager.getAllSpaces() )        &lt;b&gt;Searching for group page restrictions in space "$space.name"&lt;b&gt;      ##over each page in the current space ( WARNING THIS COULD TAKE SOME TIME ON BIG CF INSTANCES)    #foreach( $page in $pageManager.getPages( $space, true) )            &lt;ul&gt;            ##iterate over all view contentpermissionssets             #foreach( $contentPermissionSet in $contentPermissionManager.getContentPermissionSets($page,"View") )                      #foreach( $contentPermission in $contentPermissionSet )                                 ##is the current permission a user permission                    #if($contentPermission.isGroupPermission() )                                      ##if yes print the name                            &lt;li&gt;Found "VIEW" page restriction on page "$page.title" for group "$contentPermission.groupName"&lt;/li&gt;                    #end                  #end            #end        &lt;/ul&gt;         &lt;ul&gt;          ##iterate over all view contentpermissionssets         #foreach( $contentPermissionSet in $contentPermissionManager.getContentPermissionSets($page,"Edit") )                  #foreach( $contentPermission in $contentPermissionSet )                             ##is the current permission a user permission                #if($contentPermission.isGroupPermission() )                                  ##if yes print the name                    &lt;li&gt;Found "EDIT" page restriction on page "$page.title" for group "$contentPermission.groupName"&lt;/li&gt;                #end            #end        #end        &lt;/ul&gt;    #end #end
```

Testet with my Confluence 3.5.13


Tags: report

user

user-group