Class: Blacklight::AccessControls::SearchBuilder

Inherits:
SearchBuilder
  • Object
show all
Defined in:
lib/blacklight/access_controls/search_builder.rb

Overview

SearchBuilder that restricts access via Solr.

Note: solr_access_filters_logic is an Array of Symbols. It sets defaults. Each symbol identifies a method that must be in this class, taking two parameters (permission_types, ability). Can be changed in local apps or by plugins, e.g.:

Blacklight::AccessControls::SearchBuilder.solr_access_filters_logic += [:new_method]
Blacklight::AccessControls::SearchBuilder.solr_access_filters_logic.delete(:we_dont_want)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, ability:, permission_types: default_permission_types) ⇒ SearchBuilder

Returns a new instance of SearchBuilder.

Parameters:

  • scope (Object)

    typically the controller instance

  • ability (Ability)

    the current user ability

  • permission_types (Array<String>) (defaults to: default_permission_types)

    Which permission levels (logical OR) will grant you the ability to discover documents in a search.



23
24
25
26
27
28
29
30
31
# File 'lib/blacklight/access_controls/search_builder.rb', line 23

def initialize(scope, ability:, permission_types: default_permission_types)
  if self.class.included_modules.include? Blacklight::AccessControls::Enforcement
    raise 'You may not use Blacklight::AccessControls::SearchBuilder and ' \
          'include Blacklight::AccessControls::Enforcement on SearchBuilder at the same time'
  end
  super(scope)
  @ability = ability
  @permission_types = permission_types
end

Instance Attribute Details

#abilityObject (readonly)

Returns the value of attribute ability.



33
34
35
# File 'lib/blacklight/access_controls/search_builder.rb', line 33

def ability
  @ability
end

#permission_typesObject (readonly)

Returns the value of attribute permission_types.



33
34
35
# File 'lib/blacklight/access_controls/search_builder.rb', line 33

def permission_types
  @permission_types
end

Instance Method Details

#default_permission_typesObject



35
36
37
# File 'lib/blacklight/access_controls/search_builder.rb', line 35

def default_permission_types
  %w[discover read]
end