1 -- Copyright (C) The Arvados Authors. All rights reserved.
3 -- SPDX-License-Identifier: AGPL-3.0
5 CREATE TEMPORARY VIEW permission_view AS
7 perm_value (name, val) AS (
9 ('can_read', 1::smallint),
14 perm_edges (tail_uuid, head_uuid, val, follow) AS (
15 SELECT links.tail_uuid,
18 (pv.val = 3 OR groups.uuid IS NOT NULL) AS follow
20 LEFT JOIN perm_value pv ON pv.name = links.name
21 LEFT JOIN groups ON pv.val<3 AND groups.uuid = links.head_uuid
22 WHERE links.link_class = 'permission'
24 SELECT owner_uuid, uuid, 3, true FROM groups
26 perm (val, follow, user_uuid, target_uuid) AS (
27 SELECT 3::smallint AS val,
29 users.uuid::varchar(32) AS user_uuid,
30 users.uuid::varchar(32) AS target_uuid
33 SELECT LEAST(perm.val, edges.val)::smallint AS val,
34 edges.follow AS follow,
35 perm.user_uuid::varchar(32) AS user_uuid,
36 edges.head_uuid::varchar(32) AS target_uuid
38 INNER JOIN perm_edges edges
39 ON perm.follow AND edges.tail_uuid = perm.target_uuid
44 CASE follow WHEN true THEN target_uuid ELSE NULL END AS target_owner_uuid