X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f25b37a8e72716478e7cfae11ab5bf13b7051694..09cbdc3074b3f1e69c9c537875146f6da0a6ed8f:/services/api/lib/20200501150153_permission_table_constants.rb diff --git a/services/api/lib/20200501150153_permission_table_constants.rb b/services/api/lib/20200501150153_permission_table_constants.rb index acf992432d..7ee5039368 100644 --- a/services/api/lib/20200501150153_permission_table_constants.rb +++ b/services/api/lib/20200501150153_permission_table_constants.rb @@ -15,8 +15,8 @@ # update_permissions reference that file instead. PERMISSION_VIEW = "materialized_permissions" - TRASHED_GROUPS = "trashed_groups" +FROZEN_GROUPS = "frozen_groups" # We need to use this parameterized query in a few different places, # including as a subquery in a larger query. @@ -28,7 +28,7 @@ TRASHED_GROUPS = "trashed_groups" # going with the brute force approach of inlining the whole thing. # # The two substitutions are "base_case" which determines the initial -# set of permission origins and "override" which is used to ensure +# set of permission origins and "edge_perm" which is used to ensure # that the new permission takes precedence over the one in the edges # table (but some queries don't need that.) # @@ -39,9 +39,8 @@ WITH RECURSIVE union (select traverse_graph.origin_uuid, edges.head_uuid, - least(edges.val, - traverse_graph.val - %{override}), + least(%{edge_perm}, + traverse_graph.val), should_traverse_owned(edges.head_uuid, edges.val), false from permission_graph_edges as edges, traverse_graph @@ -64,7 +63,7 @@ def refresh_trashed INSERT INTO #{TRASHED_GROUPS} select ps.target_uuid as group_uuid, ps.trash_at from groups, lateral project_subtree_with_trash_at(groups.uuid, groups.trash_at) ps - where groups.owner_uuid like '_____-tpzed-_______________' + where groups.owner_uuid like '_____-tpzed-_______________' and ps.trash_at is not NULL }) end end @@ -79,8 +78,26 @@ INSERT INTO materialized_permissions #{PERM_QUERY_TEMPLATE % {:base_case => %{ select uuid, uuid, 3, true, true from users }, -:override => '' +:edge_perm => 'edges.val' } } }, "refresh_permission_view.do" end end + +def refresh_frozen + ActiveRecord::Base.transaction do + ActiveRecord::Base.connection.execute("LOCK TABLE #{FROZEN_GROUPS}") + ActiveRecord::Base.connection.execute("DELETE FROM #{FROZEN_GROUPS}") + + # Compute entire frozen_groups table, starting with top-level + # projects (i.e., project groups owned by a user). + ActiveRecord::Base.connection.execute(%{ +INSERT INTO #{FROZEN_GROUPS} +select ps.uuid from groups, + lateral project_subtree_with_is_frozen(groups.uuid, groups.frozen_by_uuid is not null) ps + where groups.owner_uuid like '_____-tpzed-_______________' + and group_class = 'project' + and ps.is_frozen +}) + end +end