Display all the groups, users of each space

Rumceisz May 13, 2012

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() && $permission.getType() == "VIEWSPACE")
    #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
#foreach ($permission in $space.getPermissions())
  #if ($permission.isGroupPermission() && $permission.getType() == "COMMENT")
    #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
#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

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

<h1>Groups</h1>
 
## get all the groups
#set ( $allGroups = $userAccessor.getGroupsAsList() )
 
## get all the spaces
#set ( $allSpaces = $spaceManager.getAllSpaces() )
 
#foreach ($group in $allGroups)
  <h2>$group</h2>
  #foreach ($space in $allSpaces)
    <h3>$space.getName()</h3>
    #foreach ($permission in $space.getPermissions())
      #if ($permission.isGroupPermission())
        #if ($permission.getGroup() == $group)
          $permission.getType()<br />
        #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: <your name>
 
## Macro loops through every group and every space listings permissions on that space grouped by group
## @noparams
 
<h1>Groups</h1>
 
## get all the groups
#set ( $allGroups = $userAccessor.getGroupsAsList() )
 
## get all the spaces
#set ( $allSpaces = $spaceManager.getAllSpaces() )
 
#foreach ($group in $allGroups)
  <h2>$group</h2>
  #foreach ($space in $allSpaces)
    <h3>$space.getName()</h3>
    #foreach ($permission in $space.getPermissions())
      #if ($permission.isGroupPermission())
        #if ($permission.getGroup() == $group)
          $permission.getType()<br />
        #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

4 answers

1 accepted

2 votes
Answer accepted
Bob Swift OSS (Bob Swift Atlassian Apps)
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.
May 13, 2012

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 (needs 2.6.0 or higher), Confluence Cache Plugin, Confluence Table Plugin

Rumceisz May 14, 2012

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

Bob Swift OSS (Bob Swift Atlassian Apps)
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.
May 14, 2012

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.

Rumceisz May 14, 2012

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).

0 votes
Roopraj Thapa June 2, 2021

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.

0 votes
Pamela Cole March 31, 2017

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

Robert Duffer January 10, 2020

Me too but 8 years later (2020)

Like daniel_spark likes this
0 votes
Rumceisz May 14, 2012

Any idea for a macro?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events