Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

how to list all the permissions of a space in confluence using groovy script

Pantham Akhil July 25, 2021

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

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2021

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.

Pantham Akhil July 26, 2021

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2021

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

Pantham Akhil July 26, 2021

Hi Nic ...the macro is not working

Nisha Patel April 27, 2023

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 28, 2023

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>

Nisha Patel April 28, 2023

Thanks @Nic Brough -Adaptavist- , I ended up fixing this.

 

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

 

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


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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events