It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do you return a list of space admins through the database?

Michael Seager Atlassian Team Nov 24, 2013

How do you return a list of space admins through the database?

2 answers

1 accepted

1 vote
Answer accepted
Tim Wong Nov 26, 2013

Possible untested improvement:

SELECT
    s.spacename AS "Space Name",
    s.spacekey  AS "Space Key",
    u.user_name AS "Admin User Name"
FROM
    cwd_user u
JOIN
    user_mapping um
ON
    u.user_name=um.username
JOIN
    cwd_membership cm
ON
    u.id=cm.child_user_id
JOIN
    cwd_group g
ON
    cm.parent_id = g.id
JOIN
    spacepermissions sp
ON
    um.user_key=sp.permusername
OR  sp.permgroupname=g.lower_group_name
JOIN
    spaces s
ON
    sp.spaceid=s.spaceid
WHERE
    sp.permtype='SETSPACEPERMISSIONS'
GROUP BY
    1,2,3
ORDER BY
    s.spacekey

I think this should result in pulling in the group memberships also. Only for 5.2.x +

Mikhail T Feb 25, 2014

Thanks! This was a great start for me... The problem I encountered was that in our DB at least (MySQL) the SPACEPERMISSIONS and SPACES table-names are capitalized. Also, I used MySQL's GROUP_CONCAT function to improve the result, getting comma-separated lists of both admin-names and admin e-mail addresses:

SELECT
    s.spacename AS "Space Name",
    s.spacekey  AS "Space Key",
    GROUP_CONCAT(DISTINCT u.display_name SEPARATOR ', ') AS "Administrator(s)",
    GROUP_CONCAT(DISTINCT u.email_address SEPARATOR ', ') AS "Administrator email address(es)"
FROM
    cwd_user u
JOIN
    user_mapping um
ON
    u.user_name=um.username
JOIN
    cwd_membership cm
ON
    u.id=cm.child_user_id
JOIN
    cwd_group g
ON
    cm.parent_id = g.id
JOIN
    SPACEPERMISSIONS sp
ON
    um.user_key=sp.permusername
OR  sp.permgroupname=g.lower_group_name
JOIN
    SPACES s
ON
    sp.spaceid=s.spaceid
WHERE
    sp.permtype='SETSPACEPERMISSIONS'
GROUP BY
    1,2
ORDER BY
    s.spacekey

0 votes
Michael Seager Atlassian Team Nov 24, 2013

NOTE: These are for individually assigned space permissions only.

In Confluence 5.2.x+:

select s.spacename as "Space Name", 
        s.spacekey as "Space Key",
        u.user_name as "Admin User Name"
from cwd_user u
join user_mapping um
        on u.user_name=um.username
join spacepermissions sp
        on um.user_key=sp.permusername
join spaces s
        on sp.spaceid=s.spaceid
where sp.permtype='SETSPACEPERMISSIONS'
order by s.spacekey;

In Confluence 3.5 - 5.1.x:

select s.spacename as "Space Name", 
        s.spacekey as "Space Key",
        u.user_name as "Admin User Name"
from cwd_user u
join spacepermissions sp
        on u.user_name=sp.permusername
join spaces s
        on sp.spaceid=s.spaceid
where sp.permtype='SETSPACEPERMISSIONS'
order by s.spacekey;

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

853 views 6 16
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you