Sha256: 509d5ef3d56afc7c9f7554fd669567c929d434c90234e6652a1160de628a17cc

Contents?: true

Size: 1.34 KB

Versions: 13

Compression:

Stored size: 1.34 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 < ::Hyrax::CollectionSearchBuilder
  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 = [query_for_my_collections]
    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, Hyrax::AdministrativeSet, ::Collection, Hyrax.config.collection_class].uniq.compact
  end

  private

  def query_for_my_collections
    query_service = Hyrax::SolrQueryService.new
    query_service.with_field_pairs(field_pairs: { depositor_ssim: current_user_key }, type: 'terms')
    query_service.with_field_pairs(field_pairs: { has_model_ssim: Hyrax.config.admin_set_model,
                                                  creator_ssim: current_user_key }, type: 'terms')
    query_service.build(join_with: 'OR')
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hyrax-5.0.0.rc2 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-5.0.0.rc1 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-3.6.0 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-4.0.0 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-4.0.0.rc3 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-4.0.0.rc2 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-4.0.0.rc1 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-3.5.0 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-4.0.0.beta2 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-3.4.2 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-4.0.0.beta1 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-3.4.1 app/search_builders/hyrax/my/collections_search_builder.rb
hyrax-3.4.0 app/search_builders/hyrax/my/collections_search_builder.rb