1 CREATE TEMPORARY VIEW permission_view AS
3 perm_value (name, val) AS (
5 ('can_read', 1::smallint),
10 perm_edges (tail_uuid, head_uuid, val, follow) AS (
11 SELECT links.tail_uuid,
14 (pv.val = 3 OR groups.uuid IS NOT NULL) AS follow
16 LEFT JOIN perm_value pv ON pv.name = links.name
17 LEFT JOIN groups ON pv.val<3 AND groups.uuid = links.head_uuid
18 WHERE links.link_class = 'permission'
20 SELECT owner_uuid, uuid, 3, true FROM groups
22 perm (val, follow, user_uuid, target_uuid) AS (
23 SELECT 3::smallint AS val,
25 users.uuid::varchar(32) AS user_uuid,
26 users.uuid::varchar(32) AS target_uuid
29 SELECT LEAST(perm.val, edges.val)::smallint AS val,
30 edges.follow AS follow,
31 perm.user_uuid::varchar(32) AS user_uuid,
32 edges.head_uuid::varchar(32) AS target_uuid
34 INNER JOIN perm_edges edges
35 ON perm.follow AND edges.tail_uuid = perm.target_uuid
40 CASE follow WHEN true THEN target_uuid ELSE NULL END AS target_owner_uuid