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?
Ä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>
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
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.
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!
OK, so I'm very grateful for this macro.
Now - it is possible to adapt this to also include space's permissions too?
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
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
It looks like you're new here. Sign in or register to get started.