From: Tom Clegg Date: Fri, 18 Jul 2014 21:37:05 +0000 (-0400) Subject: 3214: Readability: rearrange conditionals, and say "old" instead of "existing" X-Git-Tag: 1.1.0~2428^2~1 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/68aa07e5c152fd573e254614b34b71957b50ad8c 3214: Readability: rearrange conditionals, and say "old" instead of "existing" --- diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb index 469b0a3f78..5cd0c77c49 100644 --- a/services/api/app/models/arvados_model.rb +++ b/services/api/app/models/arvados_model.rb @@ -209,15 +209,17 @@ class ArvadosModel < ActiveRecord::Base if new_record? and respond_to? :owner_uuid= self.owner_uuid ||= current_user.uuid end - if owner_uuid_changed? and owner_uuid_was - # Verify permission to write to existing owner - unless current_user.uuid == self.owner_uuid_was or - current_user.uuid == self.uuid or - current_user.can? write: self.owner_uuid_was - logger.warn "User #{current_user.uuid} tried to modify #{self.class.to_s} #{uuid} but does not have permission to write existing owner_uuid #{owner_uuid_was}" - errors.add :owner_uuid, "cannot be changed without write permission on existing owner" - raise PermissionDeniedError - end + # Verify permission to write to old owner (unless owner_uuid was + # nil -- or hasn't changed, in which case the following + # "permission to write to new owner" block will take care of us) + unless !owner_uuid_changed? or + owner_uuid_was.nil? or + current_user.uuid == self.owner_uuid_was or + current_user.uuid == self.uuid or + current_user.can? write: self.owner_uuid_was + logger.warn "User #{current_user.uuid} tried to modify #{self.class.to_s} #{uuid} but does not have permission to write old owner_uuid #{owner_uuid_was}" + errors.add :owner_uuid, "cannot be changed without write permission on old owner" + raise PermissionDeniedError end # Verify permission to write to new owner unless current_user == self or current_user.can? write: owner_uuid