Know space administrators

Hello,

Is there a way to know the spaces administrators from Confluence?

Any time a user needs some permissions (read, write, etc.) of an space, we need to see who are the administrators of that space and then tell the user to ask any of them to give them the permissions.

Spaces administrators manage their groups and their users.

Is there any way that users can know the spaces administrators without asking confluence administrators?

6 answers

1 accepted

Finally got around to figuring out a different way of doing this, try the following instead:

## Macro title: Space Administrators
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Date created: 28/04/2012
## Installed by: <your name>

## Macro to list all users and groups with the permission to administer the current space.
## @noparams

<h1>Space Adminstrators</h1>
 
<p>The following users and groups have permission to administer the <strong>$space.getName()</strong> Space.</p>

<h2>Users</h2>
<table class="confluenceTable">
  <tr>
    <th class="confluenceTh">Space Administrators</th>
  </tr>
  #foreach ($permission in $space.getPermissions())
    #if ($permission.isUserPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
      <tr>
        <td class="confluenceTd">#usernameLink($permission.getUserName())</td>
      </tr>
  #end
#end
</table>

<h2>Groups</h2>
#foreach ($permission in $space.getPermissions())
  #if ($permission.isGroupPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
    #set ( $groupString = $permission.getGroup() )
    #set ( $groupObject = $userAccessor.getGroup($groupString) )
    #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )
    
    <h3>$groupString</h3>
    <table class="confluenceTable">
      <tr>
        <th class="confluenceTh">Space Administrators</th>
      </tr>
      

      #foreach ($member in $memberList)
        <tr>
          <td class="confluenceTd">#usernameLink($member)</td>
        </tr>
      #end
    </table>
  #end
#end

It looks at the permissions on a space and lists the users, groups and members of those groups rather than looking at all the users and then figuring out which groups they can administer.

Andrew.

I wanted a version of this that would report on all global (non-personal) spaces, and would ouptut everything in one table. Here's what I came up with.

## Macro title: Space Administrators
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Aaron Schmidt
## Date created: 09/27/2012
## Macro to list all users and groups with the permission to administer specified spaces.
## @noparams

#set ( $spaces = $spaceManager.getAllSpaces() )

<h1>Space Adminstrators</h1>

<table class="confluenceTable">
  <tr>
    <th class="confluenceTh">Space</th>
	<th class="confluenceTh">Key</th>
	<th class="confluenceTh">Users</th>
	<th class="confluenceTh">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="confluenceTd">
    #foreach ($permission in $space.getPermissions())
      #if ($permission.isUserPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
        #usernameLink($permission.getUserName())<br>
	  #end
	#end
    </td>
	<td class="confluenceTd">
    #foreach ($permission in $space.getPermissions())
      #if ($permission.isGroupPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
		#set ( $groupString = $permission.getGroup() )
		#set ( $groupObject = $userAccessor.getGroup($groupString) )
		#set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )
		<strong>$groupString</strong><br>
		#foreach ($member in $memberList)
		  #usernameLink($member)<br>
		#end
 	  #end
	#end
    </td>
  </tr>
  #end
#end
</table>

This is exactly what I need but we have too many spaces in our system and the macro continues to timeout. Is there any way that I could specify the spaces that I need and hard code them into the macro itself?

Fantastic! Exactly what I needed.

Hi, I added a code line that shows the Space Logo.

But it only shows the icons for the spaces the user has access too. The space names and links are fine. 

<td class="confluenceTd"><img class="space logo" width="32" height="32"
src="$spaceManager.getLogoForSpace($space.key).getDownloadPath()" alt="$space.key"/> <a  href="$req.contextPath$space.getUrlPath()">$space.getName()</a></td>

I also tried "$spaceManager.getLogoForGlobalcontext().getDownloadPath()" instead. But that change crashed the whole macro. 

Do you have any further ideas how I every user is able to see the space logos?

 

Here is the description for the spacemanager

Here the detail for the get Space Logo Class

 

And finally the whole script.

## Makro Titel: Bereich und Admins
## Kein Makrohauptteil
##
## Zeigt alle Bereiche und die Administratoren
## @noparams
 
#set ( $spaces = $spaceManager.getAllSpaces() )
 
<table class="confluenceTable">
  <tr>
    <th class="confluenceTh">Bereich</th>
    <th class="confluenceTh">Bereichsschlüssel</th>
    <th class="confluenceTh">Nutzer mit Adminrecht</th>
    <th class="confluenceTh">Gruppen mit Adminrecht</th>
  </tr>
 
#foreach ( $space in $spaces )
  #if ($space.isGlobal())
  <tr>
    #set($result=$space.getDescription().getDescriptionTitle())
 
    <td class="confluenceTd"><img class="space logo" width="32" height="32"
src="$spaceManager.getLogoForSpace($space.key).getDownloadPath()" alt="$space.key"/> <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="confluenceTd">
    #foreach ($permission in $space.getPermissions())
      #if ($permission.isUserPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
        #usernameLink($permission.getUserName())<br>
      #end
    #end
    </td>
    <td class="confluenceTd">
    #foreach ($permission in $space.getPermissions())
      #if ($permission.isGroupPermission() && $permission.getType() == "SETSPACEPERMISSIONS")
        #set ( $groupString = $permission.getGroup() )
        #set ( $groupObject = $userAccessor.getGroup($groupString) )
        #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )
        <strong>$groupString</strong><br>
        #foreach ($member in $memberList)
          #usernameLink($member)<br>
        #end
      #end
    #end
    </td>
  </tr>
  #end
#end
</table>

Hi,

Try this user macro:

## Macro title: Space Administrators
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Date created: 21/03/2012
## Installed by: <your name>
## Macro to display a list of user that are able to administer the current space.
## @noparams

#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($loginManager = $containerContext.getComponent('loginManager'))
#set($users = $userAccessor.getUsers())

<table class="confluenceTable">
  <tr>
    <th class="confluenceTh">Space Administrators</th>
  </tr>

#foreach($user in $users)
  ## list the users who can administer the current space
  #if ($permissionHelper.canAdminister($user, $space))
    <tr>
      <td class="confluenceTd">#usernameLink($user.name)</td>
    </tr>
  #end
#end
</table>

Tested on Confluence 4.1.5. It gives you a list of users who can administer a space with the profile pop-up hover so users can see their profile / contact details.

Hope that helps?

Andrew.

Just did another quick test and my macro does pick up space administrators that have picked up those permissions via a group or by being a Confluence Administrator and not just the named individual users that have been given space administrator permissions.

Excellent! Thanks Andrew.

Hi Aranxta,

Did my macro work for you? If so could you mark my answer as correct please?

Thanks,

Andrew.

Hi Andrew,

It is not working for me.

Could you tell me which option should I choose in "Macro Body Processing" and "<label for="">Output Format</label>"?

Thanks for your help!

Hi Arantxa,

Macro Body Processing should be set to "No Macro Body" so there is no "Output Format". Usage in the editor should just be {spaceadmins} (or whatever you decide to use as the Macro Name. Have a look at https://skitch.com/sphericaln/8pchi/edit-user-macro-confluence for a screenshot of how I've got it set up on my system.

Hope that helps,

Andrew.

Hi Andrew,

It may not be working for me because we are using Confluence 3.5.7, don't you think?

Hi Arantxa,

I just tried on 3.5.7 and it works, Output Format set to HTML, but all other options the same as the screenshot I previously posted.

What behaviour are you seeing? It's listing everyone? It's listing no-one? It's throwing an error?

Andrew.

Hi Andrew,

These are the steps I made:

1. Create an user macro with name spaceadmins (Macro Body Processing: No Macro Body / Output Format: HTML).

2. Copy your macro and save.

3. Create a new page in Confluence.

4. Edit the page and add only the text: {spaceadmins} (when I selected the macro, this text was added).

5. When I access to the page, it keeps thinking for a while, and then it says:

The page you are trying to access does not exist on the server

Could you try a couple of things:

  • A different title for the page
  • A page with the same title as you've been using, but without the macro on it
  • A different name for the macro
  • Making sure there are no page level restrictions on the page, or any pages above it in the hiearchy

The only time I've seen errors similar to that are when there have been special characters in the title or the macro, or if there are page level restrictions being applied.

Thanks,

Andrew.

Hi Arantxa,

Did you get any further with this?

Had another thought, didn't you have other problems with your wiki caused by a custom theme? That's not what's happening here is it? If you're seeing the "page does not exist" error in a Space that's using the custom theme could you try in a Space that's using one of the default themes?

Also, do other other macros work? Could you try creating a new one and just use the default macro template to see if it's a problem with this macro or user macros in general?

Andrew.

Hello Andrew,

I did everything you suggested but it keeps thinking and then it throws the error.

I've seen your macro and it loops through all users in Confluence and then, if the user has administrator permissions on that space, it prints it.

The problem is that we have a lot of users, too many. So I can not do this loop.

I would need to do it in the other way: Having the name of the spaces, get the users that have that permission.

I don't know if that is possible...

I appreciate your help.

Hi Arantxa,

I'll have a look, but I'm not sure if it can be done the other way around. I know that you can query a Space to find out who created it, but I'm not aware of a method on the Space object that will list users or administrators of a Space.

If I find anything I'll post back here.

Andrew.

Andrew, I have just seen your macro, it is great!! Thank you so muuuuuuuch!! :)

You're welcome. I've converted the new macro to be an answer rather than a comment, if the macro works for you could you mark it as correct so other people reading this thread know which one worked for you?

Thanks,

Andrew.

Hi Andrew

I've tested your 2nd macro in Confluence 3.5.16.

Andrew said: "Just did another quick test and my macro does pick up space administrators that have picked up those permissions via a group or by being a Confluence Administrator and not just the named individual users that have been given space administrator permissions."

That's right. It shows all members of the group confluence-administrators (in a random order) which isn't really what's needed. If it could be tweaked so the local space admin was either at the top or the bottom, I could add words to say something like "contact the person at the top of the list first".

Edited version: But don't spend any time on it on my account ... I remembered that I actually already have a working version of a macro like this [I won't name names, he knows who he is ;) ] The alternative version displays the results like this:

Administrators for Space X (SPACEX)
User: Elmer Fudd
User: Barney Rubble
System Admin: Foghorn Leghorn

... which makes it clearer who is a local admin vs who isn't.

... and yet another reason why I hate wysiwyg editors. The "code" snippet I pasted above looked fine until I edited the comment. <grumble/>

Hi Kathleen,

I think the revised macro that I already posted on this thread (the one that ended up being marked correct) does what you want? It displays the users that have explicitly been given the admin permission first and then displays the users that have inherited the permission through group membership.

Was that what you were looking for?

Cheers,

Andrew.

0 vote

Not natively, but I've seen it done with the reporting plugin, and I wrote a really simple plugin that does it as a macro (for 3.4, but probably works in most other versions), so you'll need to do some digging/coding. (From memory, the plugin I did was very simple to write)

Thank you Nic.

Is the plugin you did available for me? I'd appreciate if I could provide it.

No, it belongs to a client, so I can't distribute it without checking. (I think they'll be fine, but I also need to make time to get into the plugin exchange stuff properly. And it's for 3.4, not sure it'll work on 4.x)

Andrew's macro will do it, although I'm not sure it'll pick up groups or system-admins.

Since 5.2, this is available in the app itself:

In the Spaces Directory, choose the new Space Details icon , or go to 'Space Tools' > 'Overview' within a space to view a list of all the users who have 'Space Admin' permissions for that space.

I know this is a very old post but I tried most of these and they were very inefficient if you have a large user base..  There is no need to loop though 6000 users to find the 2 with permissiosns!  or maybe this isn't the post I was reading earlier today..  Maybe someone else added this already but the import from Atlassin Answers is too crappy to try and read.   so anyway   

These are working for me on 6.1.2.  This picks up users & groups and ommits (I think) system admins.

To list all spaces and their admins (could be a security issue if made public)

#set($spaces = $spaceManager.getAllSpaces())

<table class="confluenceTable"> 
#foreach($thisSpace in $spaces )
  #if ($thisSpace.isGlobal() )
    <tr>
       <td class="confluenceTd">
            <img class="space logo" width="32" height="32" src="$spaceManager.getLogoForSpace($thisSpace.key).getDownloadPath()" alt="$thisSpace.key"/>
            $thisSpace.getName()
       </td>
       <td class="confluenceTd">
           #set($spaceAdmins = $spaceManager.getSpaceAdmins($thisSpace  ))
           #foreach($spaceAdmin in $spaceAdmins )
              #usernameLink($spaceAdmin.name)<BR>
           #end
        </td>
    </tr>
   #end
#end
</table>

When in a space, a list for that space. (wasn't part of the question but here it is).. I use this on each space to point users to when they request permissions from the system admin. 

#set($spaceAdmins = $spaceManager.getSpaceAdmins($space))
<table class="confluenceTable">
   <tr><th class="confluenceTh">Space Administrators</th></tr>
   #foreach($spaceAdmin in $spaceAdmins )
   <tr><td class="confluenceTd">#usernameLink($spaceAdmin.name)</td></tr>
   #end
</table>

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

385 views 21 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you