require 'has_uuid'
require 'record_filters'
+require 'serializers'
class ArvadosModel < ActiveRecord::Base
self.abstract_class = true
# 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
parts = full_text_searchable_columns.collect do |column|
"coalesce(#{column},'')"
end
- # We prepend a space to the tsvector() argument here. Otherwise,
- # it might start with a column that has its own (non-full-text)
- # index, which causes Postgres to use the column index instead of
- # the tsvector index, which causes full text queries to be just as
- # slow as if we had no index at all.
- "to_tsvector('english', ' ' || #{parts.join(" || ' ' || ")})"
+ "to_tsvector('english', #{parts.join(" || ' ' || ")})"
end
def self.apply_filters query, filters
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
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
end
def log_destroy
- log_change('destroy') do |log|
+ log_change('delete') do |log|
log.fill_properties('old', etag(@old_attributes), @old_logged_attributes)
log.update_to nil
end