Class: Hyrax::Dashboard::NestedCollectionsSearchBuilder

Inherits:
CollectionSearchBuilder show all
Defined in:
app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb

Overview

Responsible for searching for collections of the same type that are not the given collection

Instance Attribute Summary collapse

Attributes inherited from CollectionSearchBuilder

#access

Instance Method Summary collapse

Methods inherited from CollectionSearchBuilder

#add_sorting_to_solr, #models, #sort_field, #with_access

Methods included from FilterByType

#filter_models

Constructor Details

#initialize(access:, collection:, scope:, nesting_attributes:, nest_direction:) ⇒ NestedCollectionsSearchBuilder

Returns a new instance of NestedCollectionsSearchBuilder.

Parameters:

  • access (Symbol)

    :edit, :read, :discover - With the given :access what all can

  • collection (Collection)
  • scope (Object)

    Typically a controller that responds to #current_ability, #blackligh_config

  • nesting_attributes (NestingAttributes)

    an object encapsulating nesting attributes of the collection

  • nest_direction (Symbol)

    (:as_parent or :as_child) the direction we are adding nesting to this collection


10
11
12
13
14
15
16
# File 'app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb', line 10

def initialize(access:, collection:, scope:, nesting_attributes:, nest_direction:)
  super(scope)
  @collection = collection
  @discovery_permissions = extract_discovery_permissions(access)
  @nesting_attributes = nesting_attributes
  @nest_direction = nest_direction
end

Instance Attribute Details

#discovery_permissionsObject (readonly)

Override for Hydra::AccessControlsEnforcement


19
20
21
# File 'app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb', line 19

def discovery_permissions
  @discovery_permissions
end

Instance Method Details

#gated_discovery_filters(permission_types = discovery_permissions, ability = current_ability) ⇒ Array<String>

If :deposit access is requested, check to see which collections the user has deposit or manage access to.

Returns:

  • (Array<String>)

    a list of filters to apply to the solr query


38
39
40
41
# File 'app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb', line 38

def gated_discovery_filters(permission_types = discovery_permissions, ability = current_ability)
  return super unless permission_types.include?("deposit")
  ["{!terms f=id}#{collection_ids_for_deposit.join(',')}"]
end

#show_only_other_collections_of_the_same_collection_type(solr_parameters) ⇒ Object


26
27
28
29
30
31
32
33
# File 'app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb', line 26

def show_only_other_collections_of_the_same_collection_type(solr_parameters)
  solr_parameters[:fq] ||= []
  solr_parameters[:fq] += [
    "-" + ActiveFedora::SolrQueryBuilder.construct_query_for_ids(limit_ids),
    ActiveFedora::SolrQueryBuilder.construct_query(Collection.collection_type_gid_document_field_name => @collection.collection_type_gid)
  ]
  solr_parameters[:fq] += limit_clause if limit_clause # add limits to prevent illegal nesting arrangements
end

#with_pagination(solr_parameters) ⇒ Object


22
23
24
# File 'app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb', line 22

def with_pagination(solr_parameters)
  solr_parameters[:rows] = 1000
end