Sha256: 06d58bf3069ff49a6f6a979fe397fe42c4cc53d72a6f0455e95f09f50b29b8e1

Contents?: true

Size: 1.38 KB

Versions: 7

Compression:

Stored size: 1.38 KB

Contents

module Spotlight
  module Catalog
    ##
    # Enforce exhibit visibility for index queries
    module AccessControlsEnforcement
      extend ActiveSupport::Concern

      included do
        self.search_params_logic += [:apply_permissive_visibility_filter, :apply_exhibit_resources_filter]
      end

      ##
      # SearchBuilder mixin
      module SearchBuilder
        extend ActiveSupport::Concern

        included do
          self.default_processor_chain += [:apply_permissive_visibility_filter, :apply_exhibit_resources_filter]
        end

        def apply_permissive_visibility_filter(solr_params)
          return unless current_exhibit
          return if scope.respond_to?(:can?) && scope.can?(:curate, current_exhibit) && !blacklight_params[:public]

          solr_params.append_filter_query "-#{Spotlight::SolrDocument.visibility_field(current_exhibit)}:false"
        end

        def apply_exhibit_resources_filter(solr_params)
          return unless Spotlight::Engine.config.filter_resources_by_exhibit && current_exhibit

          current_exhibit.solr_data.each do |facet_field, values|
            Array(values).each do |value|
              solr_params.append_filter_query send(:facet_value_to_fq_string, facet_field, value)
            end
          end
        end

        private

        def current_exhibit
          scope.current_exhibit
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
blacklight-spotlight-0.12.1 lib/spotlight/catalog/access_controls_enforcement.rb
blacklight-spotlight-0.12.0 lib/spotlight/catalog/access_controls_enforcement.rb
blacklight-spotlight-0.11.0 lib/spotlight/catalog/access_controls_enforcement.rb
blacklight-spotlight-0.10.3 lib/spotlight/catalog/access_controls_enforcement.rb
blacklight-spotlight-0.10.2 lib/spotlight/catalog/access_controls_enforcement.rb
blacklight-spotlight-0.10.1 lib/spotlight/catalog/access_controls_enforcement.rb
blacklight-spotlight-0.10.0 lib/spotlight/catalog/access_controls_enforcement.rb