Group permissions in Confluence
Asked by Rumceisz:

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


Answers:
author: Andrew Frayling
body: Hi Rumi,

Not sure if this is what you're looking for, but the following [user macro](http://confluence.atlassian.com/display/DOC/Writing+User+Macros) 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: &lt;your name&gt;## Macro to list all Spaces in an installation with the Groups that have permission to view each Space.## @noparams&lt;h1&gt;Space Group Permissions&lt;/h1&gt;&lt;p&gt;This installation contains the following Spaces and the listed groups have permission to view each Space.&lt;/p&gt;#foreach ($space in $spaceManager.getAllSpaces())  &lt;h2&gt;$space.getName()&lt;/h2&gt;  &lt;p&gt;The following groups can view the $space.getName() Space.&lt;/p&gt;  &lt;ul&gt;  #foreach ($permission in $space.getPermissions())    #if ($permission.isGroupPermission() &amp;&amp; $permission.getType() == "VIEWSPACE")      &lt;li&gt;$permission.getGroup()&lt;/li&gt;    #end  #end  &lt;/ul&gt;#end
```

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

```
#if ($permission.isGroupPermission() &amp;&amp; $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.

comments: author: Rumceisz
body: 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?


author: Andrew Frayling
body: 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.


author: Rumceisz
body: 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.


author: Andrew Frayling
body: 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.


author: Christian Czaia _Decadis AG_
body: Hey Andrew. How could I extend the macro to also list individual users?

Thx Christian


author: Andrew Frayling
body: @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.


author: Christian Czaia _Decadis AG_
body: 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


author: Andrew Frayling
body: Glad you like it :-)


author: Rumceisz
body: 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!

<br />

Rumi


author: Andrew Frayling
body: 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() &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
```

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.


author: Andrew Frayling
body: 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: &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
```

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

Andrew.


author: Rumceisz
body: 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


author: Rumceisz
body: 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.


author: Andrew Frayling
body: 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.


author: Rumceisz
body: Hi Andrew,

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


author: Andrew Frayling
body: Hi Rumi,

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

Andrew.


author: Andrew Frayling
body: Hi Rumi,

Has the requirement changed? Looking at [https://answers.atlassian.com/questions/54728/display-all-the-groups-users-of-each-space](/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.


author: Rumceisz
body: 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


author: Rumceisz
body: Hi Andrew,

can you please have a look:

<https://answers.atlassian.com/questions/59811/space-groups-and-permissions>

Thank you!

Rumi


author: David at David Simpson Apps
body: Have a look at the [Confluence data model](http://confluence.atlassian.com/display/DOC/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](http://www.divingintothedetails.com/confluence/use-sql-to-quickly-get-information-out-of-confluence/) that Betsy Walker wrote up.


author: Thomas Schlegel
body: 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


author: Rumceisz
body: If there is a script, ot would be also appropriate.


author: Rumceisz
body: Hi Christian,

well we start hoping for a feature:)

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

Regards,

Rumi


author: Christian Czaia _Decadis AG_
body: I'd be interested in this, too. Maybe some SQL script we could use? Thanks in advance, Cheers Christian


Tags: group