ScriptRunner for Confluence - Generate List of Group Permissions for ALL Spaces

I’m trying to find a way to generate a list that will show which spaces contain permissions for a specific user group. I DO NOT want this script to delete or modify any permissions, I just want the list. I looked on the forums and found a few related articles, but nothing seems to be working for me.

This script from the Adaptavist library seems like a good starting point, but I’m a newbie with scripts so I don’t know what needs to be modified to generate a list rather than remove space permissions. Also, I do not know what fields should be updated in the template to run the script (the group I’m looking into is called: WikiAnnouncers)

Adaptavist Script Example: https://library.adaptavist.com/entity/remove-space-permissions-for-a-specified-group-on-all-spaces

To generate a list of group permissions for all spaces in Confluence using ScriptRunner, you can use the following script. This script will iterate through all spaces and list the permissions assigned to each group:

import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def spaces = spaceManager.allSpaces

spaces.each { space →
def spaceKey = space.key
def spaceName = space.name
def permissions = space.permissions
def groupsWithPermissions = permissions.findAll { it.group != null }

groupsWithPermissions.each { permission ->
    def groupName = permission.groupName
    def permissionType = permission.type
    println "Space: $spaceName ($spaceKey), Group: $groupName, Permission: $permissionType"
}

}

@fcerullo thanks for the response. When I try to run the script I get the following error:

The script could not be compiled <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script7.groovy: 7: Unexpected character: '→' @ line 7, column 21. spaces.each { space → ^ 1 error </pre>.

I’ve tried manipulating your script, but nothing I do seems to work.

To fix this issue, you can replace the arrow character ‘→’ with a regular arrow ‘->’. Here’s the corrected version of the script:

import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def spaces = spaceManager.allSpaces

spaces.each { space →
def spaceKey = space.key
def spaceName = space.name
def permissions = space.permissions
def groupsWithPermissions = permissions.findAll { it.group != null }

groupsWithPermissions.each { permission ->
    def groupName = permission.groupName
    def permissionType = permission.type
    println "Space: $spaceName ($spaceKey), Group: $groupName, Permission: $permissionType"
}

}

I tried running the script with those changes, but I’m still getting the an error:

The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script5.groovy: 7: Unexpected input: '{' @ line 7, column 13. spaces.each { space -> ^ 1 error </pre>.

import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def spaces = spaceManager.allSpaces

spaces.each { space →
def spaceKey = space.key
def spaceName = space.name
def permissions = space.permissions
def groupsWithPermissions = permissions.findAll { it.group != null }

groupsWithPermissions.each { permission →
def groupName = permission.groupName
def permissionType = permission.type
println "Space: $spaceName ($spaceKey), Group: $groupName, Permission

The error message indicates that there’s an issue with the syntax of the Groovy script. It seems that the syntax { space → is not recognized.

This could happen if you’re using Groovy syntax in an environment that doesn’t support it or if there’s a typo in the script.

Here’s a corrected version of the script using a traditional loop instead of the Groovy each closure:

import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def spaces = spaceManager.allSpaces

for (space in spaces) {
def spaceKey = space.key
def spaceName = space.name
def permissions = space.permissions
def groupsWithPermissions = permissions.findAll { it.group != null }

for (permission in groupsWithPermissions) {
    def groupName = permission.groupName
    def permissionType = permission.type
    println "Space: $spaceName ($spaceKey), Group: $groupName, Permission: $permissionType"
}

}

This version should avoid the syntax issue and compile successfully. If you continue to encounter errors, double-check the syntax and ensure that your environment supports Groovy scripting.