Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to fetch list of space permissions using groovy in confluence

Pantham Akhil
Contributor
July 26, 2021

Hi All i want fetch list of confluence spaces which are enabled Anonymous access using groovy. can anyone please help me in this ..TIA

Regards 

Akhil

1 answer

0 votes
Helmy Ibrahim _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2021

Hi Akhil,

If I understand correctly, you would like to get a list of anonymous permissions of a space?

You can try the following:

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

def space = ComponentLocator.getComponent(SpaceManager).getSpace("SPACEKEY")

def anonymousPermissions = space.getPermissions().findAll { it.isAnonymousPermission() }

I hope this helps!

Cheers,
Helmy

Pantham Akhil
Contributor
July 27, 2021

Hi Helmy Thanks for your response actually the script is need to search all the spaces and list out which space has the anonymous access. this is my actual requirement.

Pantham Akhil
Contributor
July 27, 2021

And u forget to mention one more thing ...if any space is enable the anonymous access an email has to be send to me and my manger that the space is enabled anonymous access..we are new to script runner for confluence ...so can you please help us in this please...

Thanks & regards 

Akhil

Helmy Ibrahim _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2021

Hi Akhil,

Apologies for the misunderstanding!

To search for all spaces and only list those that have anonymous access, you can do the following:

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

def spaces = ComponentLocator.getComponent(SpaceManager).allSpaces

ArrayList<Space> anonymousSpaces = []

spaces.each { 
def permissions = it.getPermissions()
def hasAnonymousPermission = permissions.find { it.isAnonymousPermission() }

    if (hasAnonymousPermission) {
        anonymousSpaces.add(it)
    }
}

// Return all spaces that has at least 1 anonymous permission access
return anonymousSpaces*.getName()

To send an email, you can follow the example here.

I hope this helps!

Cheers,
Helmy

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events