X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/78ddad37d72c6c3a728530dc6932fb91f7d81b87..f90267f98880d40c3038391561c5435e531b0722:/services/api/app/models/arvados_model.rb?ds=sidebyside diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb index d5b2f871cc..a942b57e93 100644 --- a/services/api/app/models/arvados_model.rb +++ b/services/api/app/models/arvados_model.rb @@ -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