9684: update arvados_model -> recursive_stringify to convert ":foo" to "foo"
[arvados.git] / services / api / app / models / arvados_model.rb
index d5b2f871cc89a138a894753deaf9b026b0bc8443..a942b57e931fafa50e025b84b7bbd58710f65838 100644 (file)
@@ -23,6 +23,7 @@ class ArvadosModel < ActiveRecord::Base
   after_destroy :log_destroy
   after_find :convert_serialized_symbols_to_strings
   before_validation :normalize_collection_uuids
+  before_validation :set_default_owner
   validate :ensure_serialized_attribute_type
   validate :ensure_valid_uuids
 
@@ -114,6 +115,10 @@ class ArvadosModel < ActiveRecord::Base
     ["#{table_name}.modified_at desc", "#{table_name}.uuid"]
   end
 
+  def self.unique_columns
+    ["id", "uuid"]
+  end
+
   # If current user can manage the object, return an array of uuids of
   # users and groups that have permission to write the object. The
   # first two elements are always [self.owner_uuid, current user's
@@ -276,12 +281,14 @@ class ArvadosModel < ActiveRecord::Base
     true
   end
 
-  def ensure_owner_uuid_is_permitted
-    raise PermissionDeniedError if !current_user
-
-    if new_record? and respond_to? :owner_uuid=
+  def set_default_owner
+    if new_record? and current_user and respond_to? :owner_uuid=
       self.owner_uuid ||= current_user.uuid
     end
+  end
+
+  def ensure_owner_uuid_is_permitted
+    raise PermissionDeniedError if !current_user
 
     if self.owner_uuid.nil?
       errors.add :owner_uuid, "cannot be nil"
@@ -391,7 +398,7 @@ class ArvadosModel < ActiveRecord::Base
       end
       false
     else
-      (x.class == Symbol)
+      (x.class == Symbol) or (x.class == String and x.start_with?(':'))
     end
   end
 
@@ -407,7 +414,11 @@ class ArvadosModel < ActiveRecord::Base
     elsif x.is_a? Symbol
       x.to_s
     else
-      x
+      if x.is_a? String and x.start_with?(':')
+        x[1..-1]
+      else
+        x
+      end
     end
   end