1 -- Copyright (C) The Arvados Authors. All rights reserved.
3 -- SPDX-License-Identifier: AGPL-3.0
5 -- Note: this is not the current code used for permission checks (that is
6 -- materialized_permission_view), but is retained here for migration purposes.
8 CREATE TEMPORARY VIEW permission_view AS
10 perm_value (name, val) AS (
12 ('can_read', 1::smallint),
17 perm_edges (tail_uuid, head_uuid, val, follow) AS (
18 SELECT links.tail_uuid,
21 (pv.val = 3 OR groups.uuid IS NOT NULL) AS follow
23 LEFT JOIN perm_value pv ON pv.name = links.name
24 LEFT JOIN groups ON pv.val<3 AND groups.uuid = links.head_uuid
25 WHERE links.link_class = 'permission'
27 SELECT owner_uuid, uuid, 3, true FROM groups
29 perm (val, follow, user_uuid, target_uuid) AS (
30 SELECT 3::smallint AS val,
32 users.uuid::varchar(32) AS user_uuid,
33 users.uuid::varchar(32) AS target_uuid
36 SELECT LEAST(perm.val, edges.val)::smallint AS val,
37 edges.follow AS follow,
38 perm.user_uuid::varchar(32) AS user_uuid,
39 edges.head_uuid::varchar(32) AS target_uuid
41 INNER JOIN perm_edges edges
42 ON perm.follow AND edges.tail_uuid = perm.target_uuid
47 CASE follow WHEN true THEN target_uuid ELSE NULL END AS target_owner_uuid