Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to create a list "People who can view a current page"?

Alex Bobrovski July 21, 2011

Hi, I want to write a macro that generates the table (list) for a current page with names of users who have access to this page. So, if one page view is resticted to 5 people, I want to see those 5 users.

I've tried to use {report-table} and {user-reporter:space=view}, but looks like I can't get the permission list for a current page.

Pls help!

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 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 14, 2011

Hello Hello,

I would simply write a little user macro. This macro is using the contentPermissionManager to get the read permitted users. This is the code:

## @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>

Code has been testet with Confluence 4.0.3.

This code is also a demonstration for using API Managers in User Macros. Additional examples for Managers can be found here: http://www.communardo.de/home/techblog/2011/05/18/using-confluence-api-managers-in-user-macros

2 votes
Stefan Kohler
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.
July 21, 2011

Check out this plugin: https://plugins.atlassian.com/plugin/details/172

I think it does exactly what you're trying to do. I can confirm that the plugin still works with Confluence 3.5.5, we use it frequently.

Alex Bobrovski July 21, 2011

Yeah, that's a nice one, for sure. But it works 10 seconds! Every time I open this page, it is rendered so long.

Is it possible to wrap this macro in some JScript, so it will be like a button "Watch the permissions to this page...", you click it, and get the resulting table??

1 vote
Felicity Chapman February 13, 2014

This is a great macro. Thanks. Really, I'd like to be able to put it in the space header so that people know whether they are editing an externally-visible page or not. Unfortunately, it only seems to work within a page.

Is there any way to make it work in the header for the space? (That way it doesn't show up in search summaries and also it's easy to change all pages in the space.)

Simon Richardson May 5, 2016

yes please can we get this in the header space

1 vote
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
0 votes
Paul LaBarbera June 17, 2014

Anyone know why this macro doesn't work in Confluence 5.5.2? It doesn't return any users.

akiko_pusu January 4, 2015

Hi, on my environment, Confluenc 5.6, works fine.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events