Class: Hyrax::Collections::SearchService

Inherits:
Object
  • Object
show all
Includes:
Blacklight::Configurable, Blacklight::SearchHelper
Defined in:
app/services/hyrax/collections/search_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(session, user_key) ⇒ SearchService

Returns a new instance of SearchService.


7
8
9
10
11
# File 'app/services/hyrax/collections/search_service.rb', line 7

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

Instance Method Details

#apply_gated_search(solr_parameters, _user_parameters) ⇒ Object

filter that sets up access-controlled lucene query in order to provide gated search behavior

Parameters:

  • solr_parameters (Hash)

    the current solr parameters

  • _user_parameters (Hash)

    the current user-submitted parameters


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/services/hyrax/collections/search_service.rb', line 26

def apply_gated_search(solr_parameters, _user_parameters)
  solr_parameters[:fq] ||= []

  # Grant access to public content
  user_access_filters = []
  user_access_filters << "#{solr_access_control_suffix(:group)}:public"

  # Grant access based on user id & role
  if @user_key.present?
    # for roles
    ::User.group_service.roles(@user_key).each do |role|
      user_access_filters << "#{solr_access_control_suffix(:group)}:#{escape_slashes(role)}"
    end
    # for individual person access
    user_access_filters << "#{solr_access_control_suffix(:individual)}:#{escape_slashes(@user_key)}"
  end
  solr_parameters[:fq] << user_access_filters.join(' OR ')
  solr_parameters
end

#escape_slashes(value) ⇒ Object


46
47
48
# File 'app/services/hyrax/collections/search_service.rb', line 46

def escape_slashes(value)
  value.gsub('/', '\/')
end

#last_search_documentsObject

self.search_params_logic << :apply_gated_search


15
16
17
18
19
20
21
# File 'app/services/hyrax/collections/search_service.rb', line 15

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

#solr_access_control_suffix(key) ⇒ Object

Parameters:

  • key (Symbol)

    The permission type to return. Must be `:group` or `:individual`

Raises:

  • (ArgumentError)

51
52
53
54
# File 'app/services/hyrax/collections/search_service.rb', line 51

def solr_access_control_suffix(key)
  raise ArgumentError, 'you must provide :group or :individual' unless [:group, :individual].include?(key)
  Hydra.config[:permissions][:edit][key]
end