SQL query to get all Confluence spaces with anonymous enabled

Hi,

I want to get all anonymous spaces in my Confluence instance through a SQL query, however I couldn't find a decent query. I have this which returns the permissions on (all) spaces, but not the anonymous ones:

SELECT sp.permid, sp.permtype, s.spacekey, s.spacename, sp.permgroupname, um.lower_username
FROM SPACEPERMISSIONS sp
JOIN SPACES s ON sp.spaceid = s.spaceid
LEFT JOIN user_mapping um ON sp.permusername = um.user_key

i have tried with where sp.permgroupname IS NULL, but that doesn't work.

Any help or pointers in the right direction?

Marc

3 answers

1 accepted

Accepted Answer
2 votes
Stephen Deutsch Community Champion Dec 29, 2015

This might work:

SELECT *
  FROM spacepermissions
  WHERE COALESCE(permgroupname, '') = '' 
  and COALESCE(permusername, '') = '';

I got the information from this page: http://stackoverflow.com/questions/14172978/postgresql-select-empty-fields

Stephen Deutsch Community Champion Dec 29, 2015

note: anonymous permissions are those in which both group name and user name fields are blank :)

That did the trick, thank you good sir!

1 vote

Hi Marc,

If I understood you correctly, you would like to retrieve spaces which anonymous users can access correct?

This query should return all spaces which anonymous can see and access:

select distinct s.spacename
from spaces s
join spacepermissions sp on s.spaceid = sp.spaceid
where sp.permtype = 'VIEWSPACE' or 'EDITSPACE'
and permgroupname is null
and permusername is null;

The anonymous permissions are stored with the permgroupname and permusername as null.

I hope this helps!

Cheers,

Rodrigo

Hey Rodrigo, a small correction... where sp.permtype = 'VIEWSPACE' or sp.permtype ='EDITSPACE'

That also does the trick, thanks :)

What about the pages which are having anonymous permission??

Just as a hint for Oracle users, here you can use following

select distinct s.spacename
from spaces s
join spacepermissions sp on s.spaceid = sp.spaceid
where sp.permtype in ('VIEWSPACE','EDITSPACE')
and permgroupname is null
and permusername is null;

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 09, 2018 in Confluence

Introducing Praecipio Consulting, an Atlassian Solution Partner

Hey there Community!  My name is Vannya Vallejo, the Channel Communication Specialist at Atlassian and I want to help Atlassian users like you learn about our Solution Partners and how they c...

385 views 0 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you