It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Confluence User Macro needed to list all Space Admins

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 Community Leader Jan 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 Community Leader Jan 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.

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.

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

Thx for the answer but I already knew about this.

What we need is ALL space admins of all spaces.

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

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>

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 D_F likes this

Great user macro.

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

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.

Hi

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

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

2,117 views 4 5
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you