Confluence User Macro needed to list all Space Admins

Hugo January 15, 2019

Hello,

being new to Confluence Administration, could somebody please give me the code for a new User Macro that lists the usernames of alle Space administrators.

I already know about this link but don't know how to integrate the sql-query into the code part of the macro

https://confluence.atlassian.com/confkb/how-do-i-view-a-list-of-all-space-administrators-for-all-spaces-346325879.html

Thx,

Michael

https://confluence.atlassian.com/confkb/how-do-i-view-a-list-of-all-space-administrators-for-all-spaces-346325879.htmlhttps://confluence.atlassian.com/confkb/how-do-i-view-a-list-of-all-space-administrators-for-all-spaces-346325879.html

4 answers

1 accepted

0 votes
Answer accepted
Davin Studer
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.
January 15, 2019

The SQL query does not need to be integrated into the code for the user macro. They are just showing you two ways to get the data. You can use either the SQL query or the user macro. The user macro should work as is.

Davin Studer
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.
January 15, 2019

If you have a lot of users it can take a LONG time to render the page as is checks for each user against each space if that user can administer the space. In fact it may take so long that it times out.

Hugo January 18, 2019

Thank you,

the user macro did in fact time out. I have to go the sql-way because for our installation with 2000 users the macro is useless.

3 votes
Darin Hafer March 17, 2020

In Confluence 6.8.2, the Macro code provided at this link resulted in a couple issues that caused me to write it in a slightly different way. It is much more performant in my case.

I believe the biggest performance issue for me was by calling:

  • $permissionHelper.canAdminister($user, $spacer)

For Confluence 6.8.2, I changed it to:

  • $spaceManager.getSpaceAdmins($spacer)

And, I swapped the loops, and made sure to only have one row printed per space so that the 'Space Admin' table cell contains a comma-delimited list of space admins for each space.

 

My resulting code is:

## Macro title: getSpacesAndAdmins
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Darin
## Date created: dd/mm/yyyy
## Installed by: Darin

## @noparams
#set($D = "$")
#set($P = "#")

#set($users = $userAccessor.getUsers())
#set($spaces = $spaceManager.getAllSpaces())

<div id="conf-space-lister"><ul><span id="conf-space-loading" class="aui-icon aui-icon-wait">Loading...</span></ul></div>
<div id="conf-spacetbl-lister">
<table class="confluenceTable tablesorter tablesorter-default stickyTableHeaders" role="grid" resolved="" style="padding: 0px;"><colgroup><col><col><col><col></colgroup>
</table>
</div>

<pre><script>
AJS.${D}('${P}conf-space-loading').remove()
AJS.${D}('${P}conf-spacetbl-lister table').append('<tr><td colspan="4"><p><b>Found ' + $spaces.size() + ' Spaces</b><br><br></p></td></tr>');

AJS.${D}('${P}conf-spacetbl-lister table').append('<tr role="row" class="tablesorter-headerRow"><th class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="0" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" aria-sort="none" aria-label="Id: No sort applied, activate to apply an ascending sort" style="user-select: none; min-width: 8px; max-width: none;"><div class="tablesorter-header-inner">Space Id</div></th><th class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="1" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort" style="user-select: none; min-width: 8px; max-width: none;"><div class="tablesorter-header-inner">Space Name</div></th><th class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="2" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" aria-sort="none" aria-label="Value: No sort applied, activate to apply an ascending sort" style="user-select: none; min-width: 8px; max-width: none;"><div class="tablesorter-header-inner">Space Key</div></th><th class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="3" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" aria-sort="none" aria-label="Value: No sort applied, activate to apply an ascending sort" style="user-select: none; min-width: 8px; max-width: none;"><div class="tablesorter-header-inner">Space Admins</div></th></tr>');


#foreach($spacer in $spaces)
AJS.${D}('${P}conf-spacetbl-lister table').append('<tr><td class="confluenceTd">$spacer.id</td><td class="confluenceTd">$spacer.name</td><td class="confluenceTd">$spacer.key</td><td class="confluenceTd">#set($admins=$spaceManager.getSpaceAdmins($spacer)) #foreach($admin in $admins) $admin.name, #end</td></tr>');
#end


AJS.${D}('${P}conf-spacetbl-lister table').append('</tbody></table>');
</script></pre>

Darin Hafer March 17, 2020

Changed the foreach to add a hyperlink to the space listing:

 

#foreach($spacer in $spaces)
AJS.${D}('${P}conf-spacetbl-lister table').append('<tr><td class="confluenceTd">$spacer.id</td><td class="confluenceTd"><a href="$spacer.getUrlPath()">$spacer.name</a></td><td class="confluenceTd">$spacer.key</td><td class="confluenceTd">#set($admins=$spaceManager.getSpaceAdmins($spacer)) #foreach($admin in $admins) $admin.name, #end</td></tr>');
#end
Like # people like this
Katie Crick November 7, 2021

Thank you Darin!

I am wondering if there is a way to get this for all spaces EXCEPT the ones that are set to "Archive" state.  

C_ G_ November 9, 2022

Dear @Darin Hafer !

Thanks for that macro...the original macro keeps crashing here, but yours is working great!

Is it possible to list all spaces except the personal spaces (starting with "~")?

0 votes
Deleted user July 3, 2020

Great user macro.

Du you know how I could get a list such as yours but without the members of group "confluence-administrators" ?

Darin Hafer July 6, 2020

My macro does not look at the 'confluence-administrators' group.

I loops through all Spaces, and return the users who are permitted to Administer a Space.

Deleted user July 6, 2020

Hi

Yes I figured out that much and I already thought there is no easy way integrating it.

Thanks

0 votes
Victor Mutambuki [Mumo Systems]
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.
January 15, 2019

Screen Shot 2019-01-15 at 10.55.25 AM.png

Michael,

Do you only have one space? If so, go to Space Tools --> Permissions --> And at the far right, check which user(s) have Admin marked in Green.

Victor

Hugo January 15, 2019

Thx for the answer but I already knew about this.

What we need is ALL space admins of all spaces.

Victor Mutambuki [Mumo Systems]
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.
January 15, 2019

Michael,

Create a group, Confluence-Administrator, in the global permission, give the group, Confluence Administrator permission, add those that you want as admins to it. Then in each space, give the group Space Admin Permissions.

Victor

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events