3 UUID_REGEX = /^[0-9a-z]{5}-([0-9a-z]{5})-[0-9a-z]{15}$/
5 def self.included(base)
6 base.extend(ClassMethods)
7 base.validate :validate_uuid
8 base.before_create :assign_uuid
9 base.before_destroy :destroy_permission_links
10 base.has_many :links_via_head, class_name: 'Link', foreign_key: :head_uuid, primary_key: :uuid, conditions: "not (link_class = 'permission')", dependent: :restrict
11 base.has_many :links_via_tail, class_name: 'Link', foreign_key: :tail_uuid, primary_key: :uuid, conditions: "not (link_class = 'permission')", dependent: :restrict
16 Digest::MD5.hexdigest(self.to_s).to_i(16).to_s(36)[-5..-1]
19 [Server::Application.config.uuid_prefix,
21 rand(2**256).to_s(36)[-15..-1]].
29 self.respond_to? :uuid
33 if self.respond_to_uuid? and self.uuid_changed?
34 if current_user.andand.is_admin and self.uuid.is_a?(String)
35 if (re = self.uuid.match HasUuid::UUID_REGEX)
36 if re[1] == self.class.uuid_prefix
39 self.errors.add(:uuid, "type field is '#{re[1]}', expected '#{self.class.uuid_prefix}'")
43 self.errors.add(:uuid, "not a valid Arvados uuid '#{self.uuid}'")
48 self.errors.add(:uuid, "assignment not permittid")
50 self.errors.add(:uuid, "change not permitted")
60 if self.respond_to_uuid? and self.uuid.nil? or self.uuid.empty?
61 self.uuid = self.class.generate_uuid
66 def destroy_permission_links
68 Link.destroy_all(['link_class=? and (head_uuid=? or tail_uuid=?)',
69 'permission', uuid, uuid])