Sha256: 20530ab4775e6e236d5466105c51d10709ebe25f5189d1571fa6f14574fa5fd6

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

module Hydra
  module BatchEdit
    class SearchService
      include Blacklight::Configurable
      include Blacklight::SolrHelper


      def initialize(session, user_key)
        @session = session
        @user_key = user_key
        self.class.copy_blacklight_config_from(::CatalogController)
      end

      solr_search_params_logic << :apply_gated_search

      def last_search_documents 
        return [] if @session[:history].blank?
        last_search_id = @session[:history].first
        search = Search.find(last_search_id) 
        result, document_list = get_search_results(search.query_params, :fl=>'id', :rows=>1000)
        document_list
      end

      # filter that sets up access-controlled lucene query in order to provide gated search behavior
      # @param solr_parameters the current solr parameters
      # @param user_parameters the current user-subitted parameters
      def apply_gated_search(solr_parameters, user_parameters)
        solr_parameters[:fq] ||= []
        # Grant access to public content
        user_access_filters = []
        
        user_access_filters << "edit_access_group_t:public"
        
        # Grant access based on user id & role
        unless @user_key.nil?
          # for roles
          ::RoleMapper.roles(@user_key).each_with_index do |role, i|
            user_access_filters << "edit_access_group_t:#{role}"
          end
          # for individual person access
          user_access_filters << "edit_access_person_t:#{@user_key}"        
        end
        solr_parameters[:fq] << user_access_filters.join(" OR ")
        logger.debug("Solr parameters: #{ solr_parameters.inspect }")
    end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hydra-batch-edit-0.2.0 lib/hydra/batch_edit/search_service.rb
hydra-batch-edit-0.1.0 lib/hydra/batch_edit/search_service.rb
hydra-batch-edit-0.0.7 lib/hydra/batch_edit/search_service.rb
hydra-batch-edit-0.0.6 lib/hydra/batch_edit/search_service.rb
hydra-batch-edit-0.0.5 lib/hydra/batch_edit/search_service.rb