fix permissions to accommodate nodes#ping and user_sessions#create exemptions
[arvados.git] / lib / assign_uuid.rb
index b470d8ee1cc7c738c7a6f977e86ba90e273daa25..ba761e12e770b2aa02df7700269d84b114d5d5e6 100644 (file)
@@ -2,14 +2,12 @@ module AssignUuid
 
   def self.included(base)
     base.extend(ClassMethods)
-    base.validates_presence_of :uuid, :if => :respond_to_uuid?
-    base.validates_uniqueness_of :uuid, :if => :respond_to_uuid?
-    base.before_validation :assign_uuid
+    base.before_create :assign_uuid
   end
 
   module ClassMethods
     def uuid_prefix
-      Digest::MD5.hexdigest(self.to_s).to_i(16).to_s(36)[0..4]
+      Digest::MD5.hexdigest(self.to_s).to_i(16).to_s(36)[-5..-1]
     end
   end
 
@@ -21,9 +19,9 @@ module AssignUuid
 
   def assign_uuid
     return true if !self.respond_to_uuid?
-    self.uuid ||= [Server::Application.config.uuid_prefix,
-                   self.class.uuid_prefix,
-                   rand(2**256).to_s(36)[0..14]].
+    self.uuid = [Server::Application.config.uuid_prefix,
+                 self.class.uuid_prefix,
+                 rand(2**256).to_s(36)[-15..-1]].
       join '-'
   end
 end