[ARVADOS] updated: d53cf88eaa660fb410e3fe6d34edb4db38609a3d

git at public.curoverse.com git at public.curoverse.com
Sun May 11 03:02:33 EDT 2014


Summary of changes:
 services/api/app/models/api_client.rb            |  2 +-
 services/api/app/models/arvados_model.rb         | 10 ++++++++--
 services/api/app/models/authorized_key.rb        |  2 +-
 services/api/app/models/collection.rb            |  2 +-
 services/api/app/models/group.rb                 |  2 +-
 services/api/app/models/human.rb                 |  2 +-
 services/api/app/models/job.rb                   |  2 +-
 services/api/app/models/job_task.rb              |  2 +-
 services/api/app/models/keep_disk.rb             |  2 +-
 services/api/app/models/link.rb                  |  2 +-
 services/api/app/models/log.rb                   |  2 +-
 services/api/app/models/node.rb                  |  2 +-
 services/api/app/models/pipeline_instance.rb     |  2 +-
 services/api/app/models/pipeline_template.rb     |  2 +-
 services/api/app/models/repository.rb            |  2 +-
 services/api/app/models/specimen.rb              |  2 +-
 services/api/app/models/trait.rb                 |  2 +-
 services/api/app/models/user.rb                  |  2 +-
 services/api/app/models/virtual_machine.rb       |  2 +-
 services/api/config/initializers/assign_uuid.rb  |  1 -
 services/api/lib/{assign_uuid.rb => has_uuid.rb} |  5 ++++-
 services/api/test/unit/link_test.rb              | 14 +++++++++++++-
 22 files changed, 43 insertions(+), 23 deletions(-)
 delete mode 100644 services/api/config/initializers/assign_uuid.rb
 rename services/api/lib/{assign_uuid.rb => has_uuid.rb} (61%)

       via  d53cf88eaa660fb410e3fe6d34edb4db38609a3d (commit)
       via  cf32ef421c037692e7ae896f695c61d8e3670f01 (commit)
      from  34ac761cb1fd2b7b9438765d14ded85dfab0453b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit d53cf88eaa660fb410e3fe6d34edb4db38609a3d
Author: Tom Clegg <tom at curoverse.com>
Date:   Sun May 11 03:02:02 2014 -0400

    Rename assign_uuid to has_uuid to reflect expanded scope.

diff --git a/services/api/app/models/api_client.rb b/services/api/app/models/api_client.rb
index 9689074..75a800b 100644
--- a/services/api/app/models/api_client.rb
+++ b/services/api/app/models/api_client.rb
@@ -1,5 +1,5 @@
 class ApiClient < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   has_many :api_client_authorizations
diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 4faa0d0..79237b8 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -1,4 +1,5 @@
-require 'assign_uuid'
+require 'has_uuid'
+
 class ArvadosModel < ActiveRecord::Base
   self.abstract_class = true
 
diff --git a/services/api/app/models/authorized_key.rb b/services/api/app/models/authorized_key.rb
index a6bc065..5856e0c 100644
--- a/services/api/app/models/authorized_key.rb
+++ b/services/api/app/models/authorized_key.rb
@@ -1,5 +1,5 @@
 class AuthorizedKey < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   before_create :permission_to_set_authorized_user_uuid
diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb
index 600c075..745f0bf 100644
--- a/services/api/app/models/collection.rb
+++ b/services/api/app/models/collection.rb
@@ -1,5 +1,5 @@
 class Collection < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
 
diff --git a/services/api/app/models/group.rb b/services/api/app/models/group.rb
index eb11ffd..f055716 100644
--- a/services/api/app/models/group.rb
+++ b/services/api/app/models/group.rb
@@ -1,7 +1,7 @@
 require 'can_be_an_owner'
 
 class Group < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   include CanBeAnOwner
diff --git a/services/api/app/models/human.rb b/services/api/app/models/human.rb
index 3717f81..32f2906 100644
--- a/services/api/app/models/human.rb
+++ b/services/api/app/models/human.rb
@@ -1,5 +1,5 @@
 class Human < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   serialize :properties, Hash
diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb
index a239893..fbc5640 100644
--- a/services/api/app/models/job.rb
+++ b/services/api/app/models/job.rb
@@ -1,5 +1,5 @@
 class Job < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   serialize :script_parameters, Hash
diff --git a/services/api/app/models/job_task.rb b/services/api/app/models/job_task.rb
index 7d568e9..d5d2edd 100644
--- a/services/api/app/models/job_task.rb
+++ b/services/api/app/models/job_task.rb
@@ -1,5 +1,5 @@
 class JobTask < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   serialize :parameters, Hash
diff --git a/services/api/app/models/keep_disk.rb b/services/api/app/models/keep_disk.rb
index 77fc627..ee05ec2 100644
--- a/services/api/app/models/keep_disk.rb
+++ b/services/api/app/models/keep_disk.rb
@@ -1,5 +1,5 @@
 class KeepDisk < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   before_validation :ensure_ping_secret
diff --git a/services/api/app/models/link.rb b/services/api/app/models/link.rb
index 8e83a15..af39185 100644
--- a/services/api/app/models/link.rb
+++ b/services/api/app/models/link.rb
@@ -1,5 +1,5 @@
 class Link < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   serialize :properties, Hash
diff --git a/services/api/app/models/log.rb b/services/api/app/models/log.rb
index 66ba1d7..6921eca 100644
--- a/services/api/app/models/log.rb
+++ b/services/api/app/models/log.rb
@@ -1,5 +1,5 @@
 class Log < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   serialize :properties, Hash
diff --git a/services/api/app/models/node.rb b/services/api/app/models/node.rb
index 21d249b..512f0e0 100644
--- a/services/api/app/models/node.rb
+++ b/services/api/app/models/node.rb
@@ -1,5 +1,5 @@
 class Node < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   serialize :info, Hash
diff --git a/services/api/app/models/pipeline_instance.rb b/services/api/app/models/pipeline_instance.rb
index e5bd464..9ce0c4d 100644
--- a/services/api/app/models/pipeline_instance.rb
+++ b/services/api/app/models/pipeline_instance.rb
@@ -1,5 +1,5 @@
 class PipelineInstance < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   serialize :components, Hash
diff --git a/services/api/app/models/pipeline_template.rb b/services/api/app/models/pipeline_template.rb
index 3b099ed..cd0e5cb 100644
--- a/services/api/app/models/pipeline_template.rb
+++ b/services/api/app/models/pipeline_template.rb
@@ -1,5 +1,5 @@
 class PipelineTemplate < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   serialize :components, Hash
diff --git a/services/api/app/models/repository.rb b/services/api/app/models/repository.rb
index ad4a84d..f159b48 100644
--- a/services/api/app/models/repository.rb
+++ b/services/api/app/models/repository.rb
@@ -1,5 +1,5 @@
 class Repository < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
 
diff --git a/services/api/app/models/specimen.rb b/services/api/app/models/specimen.rb
index bcfcd7a..d39c612 100644
--- a/services/api/app/models/specimen.rb
+++ b/services/api/app/models/specimen.rb
@@ -1,5 +1,5 @@
 class Specimen < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   serialize :properties, Hash
diff --git a/services/api/app/models/trait.rb b/services/api/app/models/trait.rb
index 85ab236..a59c007 100644
--- a/services/api/app/models/trait.rb
+++ b/services/api/app/models/trait.rb
@@ -1,5 +1,5 @@
 class Trait < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   serialize :properties, Hash
diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb
index 2badea0..8743b92 100644
--- a/services/api/app/models/user.rb
+++ b/services/api/app/models/user.rb
@@ -1,7 +1,7 @@
 require 'can_be_an_owner'
 
 class User < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
   include CanBeAnOwner
diff --git a/services/api/app/models/virtual_machine.rb b/services/api/app/models/virtual_machine.rb
index d2830cf..094591e 100644
--- a/services/api/app/models/virtual_machine.rb
+++ b/services/api/app/models/virtual_machine.rb
@@ -1,5 +1,5 @@
 class VirtualMachine < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
 
diff --git a/services/api/config/initializers/assign_uuid.rb b/services/api/config/initializers/assign_uuid.rb
deleted file mode 100644
index d3835db..0000000
--- a/services/api/config/initializers/assign_uuid.rb
+++ /dev/null
@@ -1 +0,0 @@
-require 'assign_uuid'
diff --git a/services/api/lib/assign_uuid.rb b/services/api/lib/has_uuid.rb
similarity index 98%
rename from services/api/lib/assign_uuid.rb
rename to services/api/lib/has_uuid.rb
index 3e7c377..21369d1 100644
--- a/services/api/lib/assign_uuid.rb
+++ b/services/api/lib/has_uuid.rb
@@ -1,4 +1,4 @@
-module AssignUuid
+module HasUuid
 
   def self.included(base)
     base.extend(ClassMethods)

commit cf32ef421c037692e7ae896f695c61d8e3670f01
Author: Tom Clegg <tom at curoverse.com>
Date:   Sun May 11 02:55:45 2014 -0400

    2762: When deleting an object, delete permissions and fail if other
    links would be left dangling.

diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 69d329f..4faa0d0 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -26,7 +26,7 @@ class ArvadosModel < ActiveRecord::Base
   # Note: This only returns permission links. It does not account for
   # permissions obtained via user.is_admin or
   # user.uuid==object.owner_uuid.
-  has_many :permissions, :foreign_key => :head_uuid, :class_name => 'Link', :primary_key => :uuid, :conditions => "link_class = 'permission'"
+  has_many :permissions, :foreign_key => :head_uuid, :class_name => 'Link', :primary_key => :uuid, :conditions => "link_class = 'permission'", dependent: :destroy
 
   class PermissionDeniedError < StandardError
     def http_status
@@ -236,6 +236,11 @@ class ArvadosModel < ActiveRecord::Base
     return true
   end
 
+  def destroy_permission_links
+    Link.destroy_all(['link_class=? and (head_uuid=? or tail_uuid=?)',
+                      'permission', uuid, uuid])
+  end
+
   def ensure_permission_to_destroy
     raise PermissionDeniedError unless permission_to_destroy
   end
diff --git a/services/api/lib/assign_uuid.rb b/services/api/lib/assign_uuid.rb
index 50738aa..3e7c377 100644
--- a/services/api/lib/assign_uuid.rb
+++ b/services/api/lib/assign_uuid.rb
@@ -3,6 +3,9 @@ module AssignUuid
   def self.included(base)
     base.extend(ClassMethods)
     base.before_create :assign_uuid
+    base.before_destroy :destroy_permission_links
+    base.has_many :links_via_head, class_name: 'Link', foreign_key: :head_uuid, primary_key: :uuid, conditions: "not (link_class = 'permission')", dependent: :restrict
+    base.has_many :links_via_tail, class_name: 'Link', foreign_key: :tail_uuid, primary_key: :uuid, conditions: "not (link_class = 'permission')", dependent: :restrict
   end
 
   module ClassMethods
diff --git a/services/api/test/unit/link_test.rb b/services/api/test/unit/link_test.rb
index 72d6017..10f2b5e 100644
--- a/services/api/test/unit/link_test.rb
+++ b/services/api/test/unit/link_test.rb
@@ -4,7 +4,7 @@ class LinkTest < ActiveSupport::TestCase
   fixtures :all
 
   setup do
-    Thread.current[:user] = users(:active)
+    set_user_from_auth :admin_trustedclient
   end
 
   test 'name links with the same tail_uuid must be unique' do
@@ -45,4 +45,16 @@ class LinkTest < ActiveSupport::TestCase
       assert a.invalid?, "invalid name was accepted as valid?"
     end
   end
+
+  test "cannot delete an object referenced by links" do
+    ob = Specimen.create
+    link = Link.create(tail_uuid: users(:active).uuid,
+                       head_uuid: ob.uuid,
+                       link_class: 'test',
+                       name: 'test')
+    assert_raises(ActiveRecord::DeleteRestrictionError,
+                  "should not delete #{ob.uuid} with link #{link.uuid}") do
+      ob.destroy
+    end
+  end
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list