postgresql7.1
select * from (
select
p.pretty_name,
p.privilege,
u.party_id as grantee_id,
n.first_names || ' ' || n.last_name as grantee_name,
u.email
from
acs_permissions per, acs_privileges p, parties u,
persons n,
(select o2.object_id
from (select * from acs_objects where object_id = :object_id) o1,
acs_objects o2
where o1.tree_sortkey between o2.tree_sortkey and tree_right(o2.tree_sortkey)
and tree_ancestor_p(o2.tree_sortkey, o1.tree_sortkey)
and tree_level(o2.tree_sortkey) >= (select
case when max(tree_level(ob2.tree_sortkey)) is null
then 0
else max(tree_level(ob2.tree_sortkey))
end
from
(select *
from acs_objects
where object_id = :object_id) ob1,
acs_objects ob2
where ob1.tree_sortkey between ob2.tree_sortkey and tree_right(ob2.tree_sortkey)
and tree_ancestor_p(ob2.tree_sortkey, ob1.tree_sortkey)
and ob2.security_inherit_p = 'f')) o
where
per.privilege = p.privilege
and
per.grantee_id = u.party_id
and
per.object_id = o.object_id
and
u.party_id = n.person_id
union
select
p.pretty_name, p.privilege,
-1 as grantee_id, 'All Users' as grantee_name, ' ' as email
from
acs_permissions per, acs_privileges p, parties u
where
u.party_id = -1
and
per.object_id = :object_id
and
per.privilege = p.privilege
and
per.grantee_id = u.party_id
) tmp
order by
grantee_name, privilege