Hi everybody,
i'm trying to create a macro that will return the restricted pages for every space. I have create the following template for the macro
## Macro title: Restricted Pages ## Macro has a body: Y or N (N) ## Body processing: Selected body processing option ## Output: Selected output option ## Macro to list all restricted pages per space. ## @noparams #set ( $spaces = $spaceManager.getAllSpaces() ) #set($contentPermissionManager=$containerContext.getComponent('contentPermissionManager')) <table class="confluenceTable"> <tr> <th class="confluenceTh">Space</th> <th class="confluenceTh">Key</th> <th class="highlight-red" data-highlight-colour="red">View Page Restricted to Users</th> <th class="highlight-red" data-highlight-colour="red">View Page Restricted to Groups</th> <th class="highlight-green" data-highlight-colour="green">Edit Page Restricted to Users</th> <th class="highlight-green" data-highlight-colour="green">Edit Page Restricted to Groups</th> </tr> #foreach ( $space in $spaces ) #if ($space.isGlobal()) <tr> #set($result=$space.getDescription().getDescriptionTitle()) <td class="confluenceTd"><a href="$req.contextPath$space.getUrlPath()">$space.getName()</a></td> <td class="confluenceTd"><a href="$req.contextPath$space.getUrlPath()">$space.getKey()</a></td> <td class="highlight-red" data-highlight-colour="red"> ##In this cell i want to have the pages of space with view restriction to users </td> <td class="highlight-red" data-highlight-colour="red"> ##In this cell i want to have the pages of space with view restriction to groups </td> <td class="highlight-green" data-highlight-colour="green"> ##In this cell i want to have the pages of space with edit restriction to users </td> <td class="highlight-green" data-highlight-colour="green"> ##In this cell i want to have the pages of space with edit restriction to groups </td> </tr> #end #end </table>
The thing that i'm missing is how i will get the restricted pages per space. I had a look in Confluence's Api but i didn't manage to get the results that i want it.
For the restricted pages i would like to have both types of restriction (View and Edit)
Thanx in advance,
Kostas
Finally i have created a user macro for getting the pages with restrictions. Macro is the following
## Macro title: Restricted Pages ## Macro has a body: N ## Body processing: Selected body processing option ## Output: Selected output option ## ## Developed by: Kostas Tsolakos ## Date created: 24/04/2013 ## Installed by: Kostas Tsolakos ## Macro to display a list of pages with restrictions in current space ## @noparams ## get pagemanager #set($containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager')) #set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null)) #set($containerManager=$getInstanceMethod.invoke(null,null)) #set($containerContext=$containerManager.containerContext) #set($pageManager=$containerContext.getComponent('pageManager')) #set($pages=$pageManager.getPermissionPages($space)) #set( $edit = "Edit" ) #set( $view = "View") <table class="confluenceTable"> <tr> <th class="confluenceTh">Restricted Parent Pages</th> <th class="confluenceTh">View</th> <th class="confluenceTh">Edit</th> </tr> #if (!$pages.isEmpty()) #foreach ($page in $pages) #set($permview = $page.getContentPermissionSet($view) ) #set($permedit = $page.getContentPermissionSet($edit) ) #set ($viewuser = $permview.UserNames) #set ($edituser = $permedit.UserNames) #set ($viewgroup = $permview.GroupNames) #set ($editgroup = $permedit.GroupNames) <tr> <td> #contentLink2($page true false)<br> </td> <td> #if($viewuser || $viewgroup) #if(!$viewuser.isEmpty()) <strong>Individual Users</strong><br> #foreach($user in $viewuser) #usernameLink($user)<br> #end #end #if(!$viewgroup.isEmpty()) <strong>Groups</strong><br> #foreach($group in $viewgroup) #set ( $groupObject = $userAccessor.getGroup($group) ) #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) ) $group<br> #end #end #else No view restrictions #end </td> <td> #if($edituser || $editgroup) #if(!$edituser.isEmpty()) <strong>Individual Users</strong><br> #foreach($user in $edituser) #usernameLink($user)<br> #end #end #if(!$editgroup.isEmpty()) <strong>Groups</strong><br> #foreach($group in $editgroup) #set ( $groupObject = $userAccessor.getGroup($group) ) #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) ) $group<br> #end #end #else No edit restrictions #end </td> </tr> #end #else <tr> <td colspan="3"> There are not restricted pages in this space </td> </tr> #end </table>
I have edited a bit the macro. You can now see users and groups that have view and edit permissions on the restricted pages
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kostas, Thanks for publishing your macro but when I run it all I see is this: Restricted | Parent | Pages | View | Edit ============================== There are not restricted pages in this space Do I need to run it from another space to see them all? Please forgive my noobness, I am only just starting out with this stuff.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andy, in my answer i have put the latest version of macro. It works as expected in my Confluence instance. Which version do you use? It returns the restricted pages of the space that you use it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kostas, I am using quite an old verion (3.5). As a matter of interest, I moved the macro to another space and it returned some values, although not the ones I expected. In fact, I've just read the script comments and realised that it only returns the pages for the current space. I missed that! I have about 20 spaces. I'm guessing I need to move the macro to the space I need the report on, then run it from there?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, moving the macro to a space where there are page restrictions set seems to have worked. What I need now is a script that will produce a report for ALL spaces without having to run the macro in each space. Thanks very much for your help so far.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Bob,
thanx for the help but finally i did it by writing a simple macro and experimenting a bit with the API.
Cheers,
Kostas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I combined both examples to one user macro, that displays all restricted pages from all spaces in a single table.
## Macro title: Restricted Pages ## Macro has a body: N ## Body processing: Selected body processing option ## Output: Selected output option ## ## Developed by: Kostas Tsolakos (customized by Matthias Born) ## Date created: 24/04/2013 ## Installed by: Matthias Born ## Macro to display a list of pages with restrictions from all spaces ## @noparams ## get pagemanager #set ( $spaces = $spaceManager.getAllSpaces() ) #set($containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager')) #set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null)) #set($containerManager=$getInstanceMethod.invoke(null,null)) #set($containerContext=$containerManager.containerContext) #set($pageManager=$containerContext.getComponent('pageManager')) #set( $edit = "Edit" ) #set( $view = "View") <style type="text/css"> ul{ margin: 0 !important; } </style> <table> <colgroup> <col style="width:50%;"/> <col style="width:25%;"/> <col style="width:25%;"/> </colgroup> #foreach ($space in $spaces) #set($pages=$pageManager.getPermissionPages($space)) <tr><th><h1>$space.getName()</h1></th><th>View</th><th>Edit</th></tr> #if (!$pages.isEmpty()) #foreach ($page in $pages) #set($permview = $page.getContentPermissionSet($view) ) #set($permedit = $page.getContentPermissionSet($edit) ) #set ($viewuser = $permview.UserNames) #set ($edituser = $permedit.UserNames) #set ($viewgroup = $permview.GroupNames) #set ($editgroup = $permedit.GroupNames) <tr> <td>#contentLink2($page true false)</td> <td> #if($viewuser || $viewgroup) #if(!$viewuser.isEmpty()) <p>Individual Users</p> <ul> #foreach($user in $viewuser)<li>#usernameLink($user)</li>#end </ul> #end #if(!$viewgroup.isEmpty()) <p>Groups</p> <ul> #foreach($group in $viewgroup) #set ( $groupObject = $userAccessor.getGroup($group) ) #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) ) <li>$group</li> #end </ul> #end #else <p>No view restrictions</p> #end </td> <td> #if($edituser || $editgroup) #if(!$edituser.isEmpty()) <p>Individual Users</p> <ul> #foreach($user in $edituser)<li>#usernameLink($user)</li>#end </ul> #end #if(!$editgroup.isEmpty()) <p>Groups</p> <ul> #foreach($group in $editgroup) #set ( $groupObject = $userAccessor.getGroup($group) ) #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) ) <li>$group</li> #end </ul> #end #else <p>No edit restrictions</p> #end </td> </tr> #end #else <tr> <td colspan="3">There are not restricted pages in this space</td> </tr> #end #end </table>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.