Sha256: b87dfc787a1ad1d553d2c51aeb32a05d1e03d4e39f7646f8b90cfe3502464ca6

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true
# Added to allow for the My controller to show only things I have edit access to
class Hyrax::My::CollectionsSearchBuilder < ::SearchBuilder
  include Hyrax::My::SearchBuilderBehavior
  include Hyrax::FilterByType

  self.default_processor_chain += [:show_only_collections_deposited_by_current_user]

  # adds a filter to the solr_parameters that filters the collections and admin sets
  # the current user has deposited
  # @param [Hash] solr_parameters
  def show_only_collections_deposited_by_current_user(solr_parameters)
    clauses = [
      ActiveFedora::SolrQueryBuilder.construct_query_for_rel(depositor: current_user_key),
      ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: ::AdminSet.to_s, creator: current_user_key)
    ]
    solr_parameters[:fq] ||= []
    solr_parameters[:fq] += ["(#{clauses.join(' OR ')})"]
  end

  # This overrides the models in FilterByType
  # @return [Array<Class>] a list of classes to include
  def models
    [::AdminSet, ::Collection]
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hyrax-3.0.1 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-3.0.0 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-3.0.0.pre.rc4 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-3.0.0.pre.rc3 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-3.0.0.pre.rc2 app/search_builders/hyrax/my/collections_search_builder.rb