Display all the groups, users of each space
Asked by Rumceisz:

Hi All,

as a Confluence admin I need to achieve an overview. Hence, we have already more than 140 different spaces and 3 times more groups, it's very cumbersome to overview the space permissions, groups and users.

I'd liket to implement a macro which display the groups, permissions and users of each spaces, this way:

SpaceA

group1

permission(s) of the group in this space: e.g. VIEWONLY, ADMIN, etc.

user list of this group

group2

permission(s) of the group in this space: e.g. VIEWONLY, ADMIN, etc.

user list of this group

.....

SpaceB

groupX

permission(s) of the group in this space: e.g. VIEWONLY, ADMIN, etc.

user list of this group

.....

So, this macro would be on a page especially serves the admins to have an overview.

I got several macro code yet, which are give solutions for these features but apart:

This macro displays the groups and the group's user list of a space:

```
#foreach ($permission in $space.getPermissions())  #if ($permission.isGroupPermission() &amp;&amp; $permission.getType() == "VIEWSPACE")    #set ( $groupString = $permission.getGroup() )    #set ( $groupObject = $userAccessor.getGroup($groupString) )    #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )     &lt;h3&gt;$groupString&lt;/h3&gt;    &lt;table class="confluenceTable"&gt;      &lt;tr&gt;        &lt;th class="confluenceTh"&gt;Space Administrators&lt;/th&gt;      &lt;/tr&gt;       #foreach ($member in $memberList)        &lt;tr&gt;          &lt;td class="confluenceTd"&gt;#usernameLink($member)&lt;/td&gt;        &lt;/tr&gt;      #end    &lt;/table&gt;  #end#end#foreach ($permission in $space.getPermissions())  #if ($permission.isGroupPermission() &amp;&amp; $permission.getType() == "COMMENT")    #set ( $groupString = $permission.getGroup() )    #set ( $groupObject = $userAccessor.getGroup($groupString) )    #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )     &lt;h3&gt;$groupString&lt;/h3&gt;    &lt;table class="confluenceTable"&gt;      &lt;tr&gt;        &lt;th class="confluenceTh"&gt;Space Administrators&lt;/th&gt;      &lt;/tr&gt;       #foreach ($member in $memberList)        &lt;tr&gt;          &lt;td class="confluenceTd"&gt;#usernameLink($member)&lt;/td&gt;        &lt;/tr&gt;      #end    &lt;/table&gt;  #end#end#foreach ($permission in $space.getPermissions())  #if ($permission.isGroupPermission() &amp;&amp; $permission.getType() == "SETSPACEPERMISSIONS")    #set ( $groupString = $permission.getGroup() )    #set ( $groupObject = $userAccessor.getGroup($groupString) )    #set ( $memberList = $userAccessor.getMemberNamesAsList($groupObject) )     &lt;h3&gt;$groupString&lt;/h3&gt;    &lt;table class="confluenceTable"&gt;      &lt;tr&gt;        &lt;th class="confluenceTh"&gt;Space Administrators&lt;/th&gt;      &lt;/tr&gt;       #foreach ($member in $memberList)        &lt;tr&gt;          &lt;td class="confluenceTd"&gt;#usernameLink($member)&lt;/td&gt;        &lt;/tr&gt;      #end    &lt;/table&gt;  #end#end
```

This macro list the groups with all the spaces having access to:

```
&lt;h1&gt;Groups&lt;/h1&gt; ## get all the groups#set ( $allGroups = $userAccessor.getGroupsAsList() ) ## get all the spaces#set ( $allSpaces = $spaceManager.getAllSpaces() ) #foreach ($group in $allGroups)  &lt;h2&gt;$group&lt;/h2&gt;  #foreach ($space in $allSpaces)    &lt;h3&gt;$space.getName()&lt;/h3&gt;    #foreach ($permission in $space.getPermissions())      #if ($permission.isGroupPermission())        #if ($permission.getGroup() == $group)          $permission.getType()&lt;br /&gt;        #end      #end    #end  #end#end
```

This macro list the permissions of a group on a particular space:

```
## Macro title: Group Permissions## Macro has a body: Y or N (N)## Body processing: Selected body processing option## Output: Selected output option#### Developed by: Andrew Frayling## Date created: 06/05/2012## Installed by: &lt;your name&gt; ## Macro loops through every group and every space listings permissions on that space grouped by group## @noparams &lt;h1&gt;Groups&lt;/h1&gt; ## get all the groups#set ( $allGroups = $userAccessor.getGroupsAsList() ) ## get all the spaces#set ( $allSpaces = $spaceManager.getAllSpaces() ) #foreach ($group in $allGroups)  &lt;h2&gt;$group&lt;/h2&gt;  #foreach ($space in $allSpaces)    &lt;h3&gt;$space.getName()&lt;/h3&gt;    #foreach ($permission in $space.getPermissions())      #if ($permission.isGroupPermission())        #if ($permission.getGroup() == $group)          $permission.getType()&lt;br /&gt;        #end      #end    #end  #end#end
```

(Thanks to Andrew!)

So the features are apart but how can they achieve my requrement?

Can you please suggest?

Thanks in advance!

Rumi


Answers:
author: Bob Swift (personal)
body: This is what we use:

```
{cache:refresh=7d|showRefresh=true|showDate=true}{cli:profile=confluence|hideOutput=true|subdirectory=.} -a getSpacePermissionList --file spacePermissions.csv {cli} {csv:script=#cli/spacePermissions.csv|autoNumber=true}{csv}{cache}
```

This uses [Confluence CLI Plugin](https://bobswift.atlassian.net/wiki/display/CCLI) (needs 2.6.0 or higher), [Confluence Cache Plugin](https://bobswift.atlassian.net/wiki/display/CACHE), [Confluence Table Plugin](https://bobswift.atlassian.net/wiki/display/TBL)

comments: author: Rumceisz
body: Hi Bob,

thanks for the suggestion!

It would be the most simpliest solution, but we have a strict plugin policy, so we have to test the plugins first and then implement. Unformtunately we don't have the CLI and cache plugins?

Is there a macro for this? Or a different solution with plugins?

We don't need csv export, I would like to display on a page (like the macros I posted above).

Thanks in advance!

Rumi


author: Bob Swift (personal)
body: The CLI function can be run from the command line directly without any plugins. So, you can get the information immediately. However, if you need something to show within Confluence then you need at least some plugin. If you do the table plugin and add the csv produced by the command line as an attachment.


author: Rumceisz
body: Ok, but we don't need to export. As I see this is because the csv plugin is used. We want to display everything on a page (like the macros above).


author: Roopraj Thapa
body: This macro displays the groups and the group's user list of a space: This macro code block is not working for me.

I want to create a macro where the input parameter would be the username and the macro should return me all the space to which i have access and the information of the space.

Can anyone help me in doing this, as im completely new to the macro concept.


author: Pamela Cole
body: Are there any resolutions to this yet? 5 years later, and this is still something I need to figure out how to do? Does anyone have a solution for seeing all granular permissions for all spaces, in a concise report?

thanks, Pam

comments: author: Robert Duffer
body: Me too but 8 years later (2020)


author: Rumceisz
body: Any idea for a macro?


Tags: code

group

macro

permission