Merge branch '19146-can-write-manage'
authorTom Clegg <tom@curii.com>
Mon, 13 Jun 2022 18:30:59 +0000 (14:30 -0400)
committerTom Clegg <tom@curii.com>
Mon, 13 Jun 2022 18:30:59 +0000 (14:30 -0400)
refs #19146

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

1  2 
services/api/app/models/user.rb

index 1d1d83662c17f68b6611486624714555c6b854e2,141bccef21d63d94b1644b2c99f7f8ffd8a752d4..52d36ac57735f0c16d4b0ed6271a50681e08e05b
@@@ -72,6 -72,8 +72,8 @@@ class User < ArvadosMode
      t.add :is_invited
      t.add :prefs
      t.add :writable_by
+     t.add :can_write
+     t.add :can_manage
    end
  
    ALL_PERMISSIONS = {read: true, write: true, manage: true}
    end
  
    def can?(actions)
 -    return true if is_admin
      actions.each do |action, target|
        unless target.nil?
          if target.respond_to? :uuid
        end
        next if target_uuid == self.uuid
  
+       if action == :write && target && !target.new_record? &&
+          target.respond_to?(:frozen_by_uuid) &&
+          target.frozen_by_uuid_was
+         # Just an optimization to skip the PERMISSION_VIEW and
+         # FrozenGroup queries below
+         return false
+       end
        target_owner_uuid = target.owner_uuid if target.respond_to? :owner_uuid
  
        user_uuids_subquery = USER_UUIDS_SUBQUERY_TEMPLATE % {user: "$1", perm_level: "$3"}
  
 -      unless ActiveRecord::Base.connection.
 +      if !is_admin && !ActiveRecord::Base.connection.
          exec_query(%{
  SELECT 1 FROM #{PERMISSION_VIEW}
    WHERE user_uuid in (#{user_uuids_subquery}) and
@@@ -581,6 -592,13 +591,13 @@@ SELECT target_uuid, perm_leve
  
    protected
  
+   def self.attributes_required_columns
+     super.merge(
+                 'can_write' => ['owner_uuid', 'uuid'],
+                 'can_manage' => ['owner_uuid', 'uuid'],
+                 )
+   end
    def change_all_uuid_refs(old_uuid:, new_uuid:)
      ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |klass|
        klass.columns.each do |col|