How can I show the Page Permissions in the page itself? (Confluence)

Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

On the info page for a page it prints out a small box showing the page permissions for that page. We would really like to have this data on the page itself. Presumably there is some code to generate this information and I can't figure out what it might be.

Does anybody know?

3 answers

1 accepted

8 votes
Answer accepted
Sandro Herrmann [Communardo]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

Äehm let's extend the Macro

## @noparams
 
#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 contentPermissionManager gives you access to the page permissions
#set($contentPermissionManager=$containerContext.getComponent('contentPermissionManager')) 
 
 
Users with view Permission
<ul>
 
##iterate over all view contentpermissionssets 
#foreach( $contentPermissionSet in $contentPermissionManager.getContentPermissionSets($content,"View") )
     
    #foreach( $contentPermission in $contentPermissionSet )   
         
        ##is the current permission a user permission
        #if($contentPermission.isUserPermission() )
             
            ##if yes print the name
            <li>$contentPermission.userName</li>
        #end
 
    #end
 
#end
</ul>

Users with edit Permission
<ul>
 
##iterate over all view contentpermissionssets 
#foreach( $contentPermissionSet in $contentPermissionManager.getContentPermissionSets($content,"Edit") )
     
    #foreach( $contentPermission in $contentPermissionSet )   
         
        ##is the current permission a user permission
        #if($contentPermission.isUserPermission() )
             
            ##if yes print the name
            <li>$contentPermission.userName</li>
        #end
 
    #end
 
#end
</ul>



Groups with view Permission
<ul>
 
##iterate over all view contentpermissionssets 
#foreach( $contentPermissionSet in $contentPermissionManager.getContentPermissionSets($content,"View") )
     
    #foreach( $contentPermission in $contentPermissionSet )   
         
        ##is the current permission a user permission
        #if($contentPermission.isGroupPermission() )
             
            ##if yes print the name
            <li>$contentPermission.groupName</li>
        #end
 
    #end
 
#end
</ul>

Groups with edit Permission
<ul>
 
##iterate over all view contentpermissionssets 
#foreach( $contentPermissionSet in $contentPermissionManager.getContentPermissionSets($content,"Edit") )
     
    #foreach( $contentPermission in $contentPermissionSet )   
         
        ##is the current permission a user permission
        #if($contentPermission.isGroupPermission() )
             
            ##if yes print the name
            <li>$contentPermission.groupName</li>
        #end
 
    #end
 
#end
</ul>

Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

Here we go! Yes, that's great - the formatting is a little off but I think I can handle that - as long as I get the information then I can make it look however I want.

Thanks for your effort!

Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 23, 2011

OK, so I'm very grateful for this macro.

Now - it is possible to adapt this to also include space's permissions too?

Sandro Herrmann [Communardo]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 24, 2011

Oh yes it is.... simply add the following lines below the existing code

Space Group Permissions
<ul>
##iterate over all space permissions
#foreach( $spacePermission in $content.space.permissions)
     
            #if($spacePermission.isGroupPermission() )
              
            ##if yes print the name
            <li>$spacePermission.group ($spacePermission.type) </li>
        #end 
    
  
#end
</ul>

Space User Permissions
<ul>
##iterate over all space permissions
#foreach( $spacePermission in $content.space.permissions)
     
            #if($spacePermission.isUserPermission() )
              
                ##if yes print the name
                <li>$spacePermission.userName ($spacePermission.type) </li>
           #end 
    
  
#end
</ul>

Enjoy and rate it :) . Testet whith my CF 4

Like Thu Nguyen likes this
Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 24, 2011

I know I'm being picky here but is it possible to have the macro just print out the "View" permission for the space? I spent about 30 mins tinkering with it myself but to no avail.

Many thanks for your continued help.

Sandro Herrmann [Communardo]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 24, 2011

Simply add an additioinal condition to the if statement for the VIEW Type

Space Group Permissions
<ul>
##iterate over all space permissions
#foreach( $spacePermission in $content.space.permissions)
      
            #if($spacePermission.isGroupPermission() && $spacePermission.type == "VIEWSPACE" )
               
            ##if yes print the name
            <li>$spacePermission.group ($spacePermission.type) </li>
        #end 
     
   
#end
</ul>
 
Space User Permissions
<ul>
##iterate over all space permissions
#foreach( $spacePermission in $content.space.permissions)
      
            #if($spacePermission.isUserPermission()  && $spacePermission.type == "VIEWSPACE")
               
                ##if yes print the name
                <li>$spacePermission.userName ($spacePermission.type) </li>
           #end 
     
   
#end
</ul>

Like Thu Nguyen likes this
Stephan Haslinger November 24, 2011

Thank you! I had a similar use case. I've linked your macro in the JIRA issue https://jira.atlassian.com/browse/CONF-21661

David Yu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2012

Thanks Sandro. Works for almost all cases. One situation where this doesn't work is when a parent page has more restrictions than a child page.

For example, Bob has view restrictions on Parent, and Amy has view restrictions on Child.

The macro will show Amy having View permissions on Child but if she attempts to view it, she will be denied.

Maybe this won't be possible until there's an ability to check for effective permissions.

Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2012

Hi Sandro / everyone,

Is it possible to write some velocity to check if a *page* has no permissions set? I've written some code which checks if a *space* has a certain permission group set to it, but I want to be able to check if a page within that space has that group ALSO applied.

E.g.,:

if spacepermissions contain group:client
	$var = YES
else
	$var = NO


if pagepermissions = NULL
	$var = YES
elseif pagepermissions contain group:client
	$var = YES
else
	$ var = NO
end

I can do the first bit fine. It's the check to see if the page permissions are non-existent that I can't do. Any help to help me further this?

Cheers

0 votes
Chris Textor December 15, 2018

Hi Sandro, 

I like the code a lot.

Is there a way to show the user avatar instead of the userName?

In your code: 

##if yes print the name
<li>$contentPermission.userName</li>

 

Thanks you in advance

0 votes
Sandro Herrmann [Communardo]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

You can do this whith a little user macro. please see my example code from here:

https://answers.atlassian.com/questions/3895/how-to-create-a-list-people-who-can-view-a-current-page

Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2011

Hi Sandro,

Thanks for your answer but that doesn't achieve what I want. Your macro only shows the individual users assigned to the page. It doesn't show the user groups. Seeing as most of our permissions are set on a group-basis, this macro doesn't help me.

Thanks anyway.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events