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>
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, so I'm very grateful for this macro.
Now - it is possible to adapt this to also include space's permissions too?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you! I had a similar use case. I've linked your macro in the JIRA issue https://jira.atlassian.com/browse/CONF-21661
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.