Group permissions in Confluence

Hi All,

I would like to know which Confluence space does a group have access to? In Jira it can be check which project does a group access to. Is there a feature for Confluence too?

I need to know this because we manage some groups only for page restriction purpose so we would like to know which group gives space permission.

Thanks in advance!

Best regards,

Rumi

6 answers

1 accepted

Hi Rumi,

Not sure if this is what you're looking for, but the following user macro will loop through all of the Spaces in an installation and list the groups that have permission to view each Space.

## Macro title: Space 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: 27 Apr 2012
## Installed by: <your name>

## Macro to list all Spaces in an installation with the Groups that have permission to view each Space.
## @noparams

<h1>Space Group Permissions</h1>

<p>This installation contains the following Spaces and the listed groups have permission to view each Space.</p>

#foreach ($space in $spaceManager.getAllSpaces())
  <h2>$space.getName()</h2>
  <p>The following groups can view the $space.getName() Space.</p>
  <ul>
  #foreach ($permission in $space.getPermissions())
    #if ($permission.isGroupPermission() && $permission.getType() == "VIEWSPACE")
      <li>$permission.getGroup()</li>
    #end
  #end
  </ul>
#end

If you need to tweak it to see what other permissions a group has you can modifiy the following line:

#if ($permission.isGroupPermission() && $permission.getType() == "VIEWSPACE")

using one of the following permissions:

  • VIEWSPACE
  • COMMENT
  • EDITSPACE
  • SETSPACEPERMISSIONS
  • REMOVEPAGE
  • REMOVECOMMENT
  • REMOVEBLOG
  • CREATEATTACHMENT
  • REMOVEATTACHMENT
  • EDITBLOG
  • EXPORTPAGE
  • EXPORTSPACE
  • REMOVEMAIL
  • SETPAGEPERMISSIONS

Hope that helps?

Andrew.

Hi Andrew,

I created this macro to our Confluence, but where can we get the results? Is there a display where I can get the result? Or have to be added a page?

Hi Rumi,

If you've created a user macro you should be able to see the results by using {your macro name} on any standard page in Confluence, e.g. {spacegroups}

You may want to create a dedicated page for it as the output is going to be lengthy if you have a lot of Spaces and Groups, but you should be able to use the macro anywhere.

Does that help?

Andrew.

Hi Andrew,

many thanks for the macro, it works.

Another question: how should be changed the script to list it reverse? I mean not by list the spaces one by one, but the groups in ascending order and list which space(s) has the group permission?

Like this:

group1

has permission (at least viewonly) to the following spaces:

SpaceA

SpaceB

.....

group2

has permission (at least viewonly) to the following spaces:

SpaceC

SpaceA

etc.

Hi Rumi,

I'll have a look and get back to you - it might be a bit resource intensive as (off the top of my head) it would have to loop through every Space for every Group as I don't think there's anything on a Group object that tells you what Spaces it can access.

Should be do-able, but it might be slow to render on large installs.

Andrew.

Hey Andrew. How could I extend the macro to also list individual users?

Thx Christian

@Christian, have a look at a post (http://blog.networkedcollaboration.com/2012/04/28/confluence-space-administrators-remixed/) I wrote for something similar to what you're looking for. For the code in the post just change "SETSPACEPERMISSIONS" to "VIEWSPACE"

Andrew.

Nice, I was just looking at it at the moment. I just sort of googled you and followed the link to your blog :-) Greta work. Cheers Christian

Glad you like it :-)

Hi Andrew,

I checked your macro for member list of admin users (http://blog.networkedcollaboration.com/2012/04/28/confluence-space-administrators-remixed/).

Hence, I am a VB developer, I couldn't edit the code: I would like to extend this macro with the following: listing the groups with read only permission, and then in the next section with comment permission and at the end list with admin permission. I tired to insert an 'elseif' statement but it didn't work for me. It may be a very easy script but I'm not very familiar with this scripting.

Thanks in advance!


Rumi

Hi Rumi,

The easiest way with that macro is to just duplicate the following code block 3 times:

#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

Once with $permission.getType() == "VIEWSPACE" , once with $permission.getType() == "COMMENT" and once with $permission.getType() == "SETSPACEPERMISSIONS"

Not the prettiest way of doing it, but it should do what you want.

Hope that helps?

Andrew.

Hi Rumi,

Here's another version of the macro which lists all the groups with the permissions they have on each 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

The formatting is not very pretty, but it should give you the information you wanted grouped by group.

Andrew.

Hi Andrew,

the last one works! It's fantastic. Thanks you very much!!!

For each groups all the spaces and personal spaces are listed, not just those the group has permission. How can change the script that only those spaces/personal spaces will be listed that the group have permissions to. Hence, we have about 70 spaces and 20-25 personal spaces.

Something:

#if ($permission.isGroupPermission()) <> ""
but it didn't work for me.

Thanks you again!

Rumi

Hi Andrew,

is there any way that uses 'if' statement in the code above?

I mean, when I inserted the code 3 times, it will display many groups 2 or 3 times.

I feel sorry for exploiting you, but I am not very good in this script.

Many thanks!

Rumi

Hi Rumi,

The easiest way with that macro is to just duplicate the following code block 3 times:

#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

Once with $permission.getType() == "VIEWSPACE" , once with $permission.getType() == "COMMENT" and once with $permission.getType() == "SETSPACEPERMISSIONS"

Not the prettiest way of doing it, but it should do what you want.

Hope that helps?

Andrew.

Hi Rumi,

I've been looking at a better way to present the permissions info, but I haven't got it figured out yet. Will post back here if and when I do.

Andrew.

Hi Andrew,

have you found something to solve this DEvnull. I also triing a code.

Hi Rumi,

Sorry, not had chance to look at this properly yet.

Andrew.

Hi Rumi,

Has the requirement changed? Looking at https://answers.atlassian.com/questions/54728/display-all-the-groups-users-of-each-space that's a different requirement to what's being asked here. This thread asks for permissions grouped by group and the other thread asks for permissions grouped by space.

Andrew.

Hi Andrew,

yes the users clarified at last. Sorry, for confusing you in the above comments.

What we would like to achieve on a page is the following:we admins need to see all the spaces in our Confluence instance. Under each space all the related groups would listed with the permissions the group grants in that particular space. And under the group all the group members would be listed in a table.

This is how it would look like:

SpaceA

group1

permissions: VIEW, EXPORT, RESTRICT PAGE, etc...

group members:

John Doe

Gary Smith

.....

group113

permissions: VIEW

group members:

Kate Jacobs

...

SpaceB

group1

permissions: VIEW, EXPORT, RESTRICT PAGE, ADMIN, etc...

group members:

John Doe

Gary Smith

.....

Of course the formatting doesn't matter.

You posted macros for all the features above, but apart. I tried to concatenate these macro scripts but I am layman in this scripting language.

Many thanks for your helps so far!

Rumi

1 vote
David Simpson Community Champion Apr 25, 2012

Have a look at the Confluence data model and create your own SQL statement. Blog about your results (or add them here as a comment) :)

Related: Here's a bunch of SQL scripts that Betsy Walker wrote up.

I'd be interested in this, too. Maybe some SQL script we could use? Thanks in advance, Cheers Christian

Hi Christian,

well we start hoping for a feature:)

I am convinced that this a wide range of claim here.

Regards,

Rumi

If there is a script, ot would be also appropriate.

0 vote
Thomas Schlegel Community Champion Apr 25, 2012

Hi Rumi,

great request :-)

I'm wondering why noone else has requested this before. Maybe you should open a feature request and post the link here, so everyone can vote for it.

Best regards

Thomas

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

375 views 20 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