Merge branch '21666-provision-test-improvement'
[arvados.git] / services / api / lib / can_be_an_owner.rb
index 6f30f5ae33801afabd6c6a5e3fa6805c05e628fa..995f6f334c3ab48e7b82a14755ad0dcde7bb58ac 100644 (file)
@@ -14,16 +14,28 @@ module CanBeAnOwner
     # record when other objects refer to it.
     ActiveRecord::Base.connection.tables.each do |t|
       next if t == base.table_name
-      next if t == 'schema_migrations'
-      next if t == 'permission_refresh_lock'
-      next if t == 'ar_internal_metadata'
-      next if t == 'commit_ancestors'
-      next if t == 'commits'
+      next if t.in?([
+                      'schema_migrations',
+                      'permission_refresh_lock',
+                      'ar_internal_metadata',
+                      'commit_ancestors',
+                      'commits',
+                      'humans',
+                      'jobs',
+                      'job_tasks',
+                      'keep_disks',
+                      'nodes',
+                      'pipeline_instances',
+                      'pipeline_templates',
+                      'repositories',
+                      'specimens',
+                      'traits',
+                    ])
       klass = t.classify.constantize
       next unless klass and 'owner_uuid'.in?(klass.columns.collect(&:name))
       base.has_many(t.to_sym,
-                    foreign_key: :owner_uuid,
-                    primary_key: :uuid,
+                    foreign_key: 'owner_uuid',
+                    primary_key: 'uuid',
                     dependent: :restrict_with_exception)
     end
     # We need custom protection for changing an owner's primary
@@ -62,7 +74,7 @@ module CanBeAnOwner
                   # "name" arg is a query label that appears in logs:
                   "descendant_project_uuids for #{self.uuid}",
                   # "binds" arg is an array of [col_id, value] for '$1' vars:
-                  [[nil, self.uuid], [nil, 'project']],
+                  [self.uuid, 'project'],
                   ).rows.map do |project_uuid,|
       project_uuid
     end
@@ -75,7 +87,7 @@ module CanBeAnOwner
 
     # Check for objects that have my old uuid listed as their owner.
     self.class.reflect_on_all_associations(:has_many).each do |assoc|
-      next unless assoc.foreign_key == :owner_uuid
+      next unless assoc.foreign_key == 'owner_uuid'
       if assoc.klass.where(owner_uuid: uuid_was).any?
         errors.add(:uuid,
                    "cannot be changed on a #{self.class} that owns objects")