X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cef69b16e1295e456548813ad95c9db827136c17..6c14ca8fe128f4db3bafe4edd1cc5551bc85e1ef:/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 9442a6f0ee..1fe5808848 100644 --- a/services/api/app/models/arvados_model.rb +++ b/services/api/app/models/arvados_model.rb @@ -4,6 +4,7 @@ class ArvadosModel < ActiveRecord::Base self.abstract_class = true include CurrentApiClient # current_user, current_api_client, etc. + include DbCurrentTime attr_protected :created_at attr_protected :modified_by_user_uuid @@ -56,6 +57,12 @@ class ArvadosModel < ActiveRecord::Base "#{current_api_base}/#{self.class.to_s.pluralize.underscore}/#{self.uuid}" end + def self.selectable_attributes(template=:user) + # Return an array of attribute name strings that can be selected + # in the given template. + api_accessible_attributes(template).map { |attr_spec| attr_spec.first.to_s } + end + def self.searchable_columns operator textonly_operator = !operator.match(/[<=>]/) self.columns.select do |col| @@ -96,6 +103,10 @@ class ArvadosModel < ActiveRecord::Base api_column_map end + def self.default_orders + ["#{table_name}.modified_at desc", "#{table_name}.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 @@ -206,6 +217,25 @@ class ArvadosModel < ActiveRecord::Base attributes end + def self.full_text_searchable_columns + self.columns.select do |col| + if col.type == :string or col.type == :text + true + end + end.map(&:name) + end + + def self.full_text_tsvector + tsvector_str = "to_tsvector('english', " + first = true + self.full_text_searchable_columns.each do |column| + tsvector_str += " || ' ' || " if not first + tsvector_str += "coalesce(#{column},'')" + first = false + end + tsvector_str += ")" + end + protected def ensure_ownership_path_leads_to_user @@ -329,9 +359,10 @@ class ArvadosModel < ActiveRecord::Base end def update_modified_by_fields - self.updated_at = Time.now + current_time = db_current_time + self.updated_at = current_time self.owner_uuid ||= current_default_owner if self.respond_to? :owner_uuid= - self.modified_at = Time.now + self.modified_at = current_time self.modified_by_user_uuid = current_user ? current_user.uuid : nil self.modified_by_client_uuid = current_api_client ? current_api_client.uuid : nil true