X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fb3c02b38a24cda422de95f2f8b49002b841cc72..7a98271d94163cdc4afa5bfcf275db353bc062d2:/services/api/app/models/link.rb diff --git a/services/api/app/models/link.rb b/services/api/app/models/link.rb index 5ca5f36004..26e7183be3 100644 --- a/services/api/app/models/link.rb +++ b/services/api/app/models/link.rb @@ -1,4 +1,4 @@ -class Link < OrvosModel +class Link < ArvadosModel include AssignUuid include KindAndEtag include CommonApiTemplate @@ -8,19 +8,15 @@ class Link < OrvosModel after_update :maybe_invalidate_permissions_cache after_create :maybe_invalidate_permissions_cache after_destroy :maybe_invalidate_permissions_cache + attr_accessor :head_kind, :tail_kind - attr_accessor :head - attr_accessor :tail - - api_accessible :superuser, :extend => :common do |t| - t.add :tail_kind + api_accessible :user, extend: :common do |t| t.add :tail_uuid t.add :link_class t.add :name - t.add :head_kind t.add :head_uuid - t.add :head, :if => :head - t.add :tail, :if => :tail + t.add :head_kind + t.add :tail_kind t.add :properties end @@ -29,6 +25,18 @@ class Link < OrvosModel super end + def head_kind + if k = ArvadosModel::resource_class_for_uuid(head_uuid) + k.kind + end + end + + def tail_kind + if k = ArvadosModel::resource_class_for_uuid(tail_uuid) + k.kind + end + end + protected def permission_to_attach_to_objects @@ -43,11 +51,11 @@ class Link < OrvosModel # All users can grant permissions on objects they own head_obj = self.class. - kind_class(self.head_kind). + kind_class(self.head_uuid). where('uuid=?',head_uuid). first if head_obj - return true if head_obj.owner == current_user.uuid + return true if head_obj.owner_uuid == current_user.uuid end # Users with "can_grant" permission on an object can grant