how to list all the permissions of a space in confluence using groovy script
Asked by Pantham Akhil:

Hi all i am new to confluence and we are using script runner for confluence and we want list of permissions which a space have using groovy ..can anyone help me in this ..TIA


Answers:
author: Nic Brough -Adaptavist-
body: What are you actually trying to achieve with this?

Most "I want to see the permissions of a space" questions can be answered by "look at the space permissions page in admin". A request to do it with a script suggests you want to actually do something more clever, and rather than just give you a piece of it, it may be that we can give you a script that can do most of the task.

comments: author: Pantham Akhil
body: Hi Nic tnq for the quick response actually we want get the spaces list which were enabled the anonymous access by script runner for confluence for that we need a script can you please help me in this...


author: Nic Brough -Adaptavist-
body: Ah, that makes sense.

I don't have a script for that, but I have a user-macro bookmarked that does something similar and could be adapted easily (a user-macro is probably a bit more useful than a script in this case, because you can put it on a page restricted to admins and then visit the page whenever you need it, rather than go look for a script every time).

This in fact lists all your administrators

```
#set($spaces = $spaceManager.getAllSpaces())<table class="confluenceTable"> #foreach($thisSpace in $spaces )  #if ($thisSpace.isGlobal() )    <tr>       <td class="confluenceTd">            <img class="space logo" width="32" height="32" src="$spaceManager.getLogoForSpace($thisSpace.key).getDownloadPath()" alt="$thisSpace.key"/>            $thisSpace.getName()       </td>       <td class="confluenceTd">           #set($spaceAdmins = $spaceManager.getSpaceAdmins($thisSpace  ))           #foreach($spaceAdmin in $spaceAdmins )              #usernameLink($spaceAdmin.name)<BR>           #end        </td>    </tr>   #end#end</table>
```

But you could replace the "set($spaceadmins = ..." area with something like

#set($permissions = $thisSpace.getPermissions())

#foreach($perm in $permissions)

$perm \<BR\>

#end

This would give you everything, which might be a bit much, I'd probably want to put in an "if" to only dump out the permissions I'm interested in


author: Pantham Akhil
body: Hi Nic ...the macro is not working


author: Nisha Patel
body: Thanks, this was so helpful! Do you know how to have all the spaces have a hyperlink back to the space?


author: Nic Brough -Adaptavist-
body: You could change the code in the macro so that it embeds HTML links - I'd do it in the space name text myself. Instead of

$thisSpace.getName()

try something like the below (untested, I can't remember how to get the base URL, and I'm not sure the getKey is right)

\<a href="\<baseurl\>/display/$thisSpace.getKey()"\>$thisSpace.getName()\</a\>


author: Nisha Patel
body: Thanks [@Nic Brough -Adaptavist-](/t5/user/viewprofilepage/user-id/781454) , I ended up fixing this.

**However, do you know how to show only active users:**

#set($spaces = $spaceManager.getAllSpaces())

<br />

\<table class="confluenceTable"\>  
\<thead\>  
\<tr\>  
\<th\>Space Name\</th\>  
\<th\>Space Administrator\</th\>  
\</tr\>  
\</thead\>

#foreach($thisSpace in $spaces )  
#if ($thisSpace.isGlobal() )  
\<tr\>  
\<td class="confluenceTd"\>  
\<img class="space logo" width="32" height="32" src="$spaceManager.getLogoForSpace($thisSpace.key).getDownloadPath()" alt="$thisSpace.key" /\>  
\<a href="$thisSpace.getUrlPath()"\>$thisSpace.name\</a\>\</td\>

\<td class="confluenceTd"\>  
#set($spaceAdmins = $spaceManager.getSpaceAdmins($thisSpace ))  
#foreach($spaceAdmin in $spaceAdmins )  
#usernameLink($spaceAdmin.name)\<BR\>  
#end  
\</td\>  
\</tr\>  
#end  
#end  
\</table\>


Tags: confluence-server

scriptrunner

server