X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4115524460e89f36b99f2fb5de1adebd86daaf4a..594e00f9311da95f73843f55b6e1c7c3ad55d8df:/services/api/app/models/arvados_model.rb diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb index 910db7e0c7..0419dadafb 100644 --- a/services/api/app/models/arvados_model.rb +++ b/services/api/app/models/arvados_model.rb @@ -1,5 +1,6 @@ require 'has_uuid' require 'record_filters' +require 'serializers' class ArvadosModel < ActiveRecord::Base self.abstract_class = true @@ -32,7 +33,11 @@ class ArvadosModel < ActiveRecord::Base # Note: This only returns permission links. It does not account for # permissions obtained via user.is_admin or # user.uuid==object.owner_uuid. - has_many :permissions, :foreign_key => :head_uuid, :class_name => 'Link', :primary_key => :uuid, :conditions => "link_class = 'permission'" + has_many(:permissions, + foreign_key: :head_uuid, + class_name: 'Link', + primary_key: :uuid, + conditions: "link_class = 'permission'") class PermissionDeniedError < StandardError def http_status @@ -450,6 +455,20 @@ class ArvadosModel < ActiveRecord::Base end end + def self.where_serialized(colname, value) + sorted = deep_sort_hash(value) + where("#{colname.to_s} IN (?)", [sorted.to_yaml, SafeJSON.dump(sorted)]) + end + + Serializer = { + Hash => HashSerializer, + Array => ArraySerializer, + } + + def self.serialize(colname, type) + super(colname, Serializer[type]) + end + def ensure_serialized_attribute_type # Specifying a type in the "serialize" declaration causes rails to # raise an exception if a different data type is retrieved from @@ -597,7 +616,7 @@ class ArvadosModel < ActiveRecord::Base if self == ArvadosModel # If called directly as ArvadosModel.find_by_uuid rather than via subclass, # delegate to the appropriate subclass based on the given uuid. - self.resource_class_for_uuid(uuid).find_by_uuid(uuid) + self.resource_class_for_uuid(uuid).unscoped.find_by_uuid(uuid) else super end