- def assign_uuid
- return true if !self.respond_to_uuid?
- if (uuid.is_a?(String) and uuid.length>0 and
- current_user and current_user.is_admin)
+ def validate_uuid
+ if self.respond_to_uuid? and self.uuid_changed?
+ if current_user.andand.is_admin and self.uuid.is_a?(String)
+ if (re = self.uuid.match HasUuid::UUID_REGEX)
+ if re[1] == self.class.uuid_prefix
+ return true
+ else
+ self.errors.add(:uuid, "type field is '#{re[1]}', expected '#{self.class.uuid_prefix}'")
+ return false
+ end
+ else
+ self.errors.add(:uuid, "not a valid Arvados uuid '#{self.uuid}'")
+ return false
+ end
+ else
+ if self.new_record?
+ self.errors.add(:uuid, "assignment not permitted")
+ else
+ self.errors.add(:uuid, "change not permitted")
+ end
+ return false
+ end
+ else