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

1 vote
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!

0 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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

345 views 20 10
Join discussion

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