Merge branch 'jszlenk/create_new_subproject' refs #21937
[arvados.git] / services / api / app / models / computed_permission.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'record_filters'
6
7 class ComputedPermission < ApplicationRecord
8   self.table_name = 'materialized_permissions'
9   include CurrentApiClient
10   include CommonApiTemplate
11   extend RecordFilters
12
13   PERM_LEVEL_S = ['none', 'can_read', 'can_write', 'can_manage']
14
15   api_accessible :user do |t|
16     t.add :user_uuid
17     t.add :target_uuid
18     t.add :perm_level_s, as: :perm_level
19   end
20
21   protected
22
23   def perm_level_s
24     PERM_LEVEL_S[perm_level]
25   end
26
27   def self.default_orders
28     ["#{table_name}.user_uuid", "#{table_name}.target_uuid"]
29   end
30
31   def self.readable_by(*args)
32     self
33   end
34
35   def self.searchable_columns(operator)
36     if !operator.match(/[<=>]/) && !operator.in?(['in', 'not in'])
37       []
38     else
39       ['user_uuid', 'target_uuid']
40     end
41   end
42
43   def self.limit_index_columns_read
44     []
45   end
46
47   def self.selectable_attributes
48     %w(user_uuid target_uuid perm_level)
49   end
50
51   def self.columns_for_attributes(select_attributes)
52     select_attributes
53   end
54
55   def self.serialized_attributes
56     {}
57   end
58
59   def self.unique_columns
60     []
61   end
62 end