diff --git a/app/services/hyrax/collection_member_service.rb b/app/services/hyrax/collection_member_service.rb index ca82edfa36..6aba299d94 100644 --- a/app/services/hyrax/collection_member_service.rb +++ b/app/services/hyrax/collection_member_service.rb @@ -31,5 +31,7 @@ def list_collections def collection_search_builder @collection_search_builder ||= ParentCollectionSearchBuilder.new([:include_item_ids, :add_paging_to_solr, :add_access_controls_to_solr_params], self) end + + def search_state_class; end end end diff --git a/app/services/hyrax/embargo_service.rb b/app/services/hyrax/embargo_service.rb index d36cbbfcc1..688c843391 100644 --- a/app/services/hyrax/embargo_service.rb +++ b/app/services/hyrax/embargo_service.rb @@ -26,6 +26,10 @@ def assets_with_deactivated_embargoes presenters(builder) end + def search_state_class + nil + end + private def presenter_class diff --git a/app/services/hyrax/lease_service.rb b/app/services/hyrax/lease_service.rb index 8455f05e65..2f1d3f4873 100644 --- a/app/services/hyrax/lease_service.rb +++ b/app/services/hyrax/lease_service.rb @@ -22,6 +22,10 @@ def assets_with_deactivated_leases presenters(builder) end + def search_state_class + nil + end + private def presenter_class diff --git a/app/services/hyrax/statistics/depositors/summary.rb b/app/services/hyrax/statistics/depositors/summary.rb index 0370b1bf8b..5585805bf1 100644 --- a/app/services/hyrax/statistics/depositors/summary.rb +++ b/app/services/hyrax/statistics/depositors/summary.rb @@ -33,7 +33,7 @@ def depositors private - delegate :blacklight_config, to: CatalogController + delegate :blacklight_config, :search_state_class, to: CatalogController delegate :depositor_field, to: DepositSearchBuilder # results come from Solr in an array where the first item is the user and diff --git a/hyrax.gemspec b/hyrax.gemspec index b7ea7d9712..f67387cdd1 100644 --- a/hyrax.gemspec +++ b/hyrax.gemspec @@ -35,7 +35,7 @@ SUMMARY spec.add_dependency 'active-fedora', '~> 13.1', '>= 13.1.2' spec.add_dependency 'almond-rails', '~> 0.1' spec.add_dependency 'awesome_nested_set', '~> 3.1' - spec.add_dependency 'blacklight', '< 7.25' + spec.add_dependency 'blacklight', '~> 7.25' spec.add_dependency 'blacklight-gallery', '~> 4.0' spec.add_dependency 'breadcrumbs_on_rails', '~> 3.0' spec.add_dependency 'browse-everything', '>= 0.16', '< 2.0' diff --git a/lib/hyrax/engine.rb b/lib/hyrax/engine.rb index c049ea319f..f6469e780a 100644 --- a/lib/hyrax/engine.rb +++ b/lib/hyrax/engine.rb @@ -80,6 +80,10 @@ class Engine < ::Rails::Engine message += "It is UNEXPECTED if you are booting up a Hyrax powered application via `rails server'" Rails.logger.info(message) end + + # Force CatalogController to use our SearchState class, which has an important + # work-around for some highly suspect SPARQL-gem monkeypatching. + CatalogController.search_state_class = Hyrax::SearchState if CatalogController.search_state_class == Blacklight::SearchState end initializer 'requires' do diff --git a/lib/hyrax/search_state.rb b/lib/hyrax/search_state.rb index 9fc876ad0a..396eba6928 100644 --- a/lib/hyrax/search_state.rb +++ b/lib/hyrax/search_state.rb @@ -9,5 +9,14 @@ def url_for_document(doc, _options = {}) return [hyrax, doc] if doc.collection? [main_app, doc] end + + # The SPARQL gem stomps on the Rails definition of deep_dup and gives us a Hash instead of + # a HashWithIndifferentAccess. This is an ugly workaround to get the right contract with + # the upstream class. + # https://github.com/ruby-rdf/sparql/blob/develop/lib/sparql/algebra/extensions.rb#L238-L244 + def to_hash + super.with_indifferent_access + end + alias to_h to_hash end end diff --git a/spec/helpers/hyrax/collections_helper_spec.rb b/spec/helpers/hyrax/collections_helper_spec.rb index 0614eee171..7050bdbe76 100644 --- a/spec/helpers/hyrax/collections_helper_spec.rb +++ b/spec/helpers/hyrax/collections_helper_spec.rb @@ -20,6 +20,7 @@ allow(controller).to receive(:blacklight_config).and_return(bl_config) allow(controller).to receive(:repository).and_return(repository) allow(controller).to receive(:current_ability).and_return(ability) + allow(controller).to receive(:search_state_class).and_return(nil) end it 'gives an empty set for a missing collection' do diff --git a/spec/models/collection_spec.rb b/spec/models/collection_spec.rb index 655ff8d71a..26be120ab6 100644 --- a/spec/models/collection_spec.rb +++ b/spec/models/collection_spec.rb @@ -307,7 +307,7 @@ class Member < ActiveFedora::Base let(:blacklight_config) { CatalogController.blacklight_config } let(:repository) { Blacklight::Solr::Repository.new(blacklight_config) } let(:current_ability) { instance_double(Ability, admin?: true) } - let(:scope) { double('Scope', can?: true, current_ability: current_ability, repository: repository, blacklight_config: blacklight_config) } + let(:scope) { double('Scope', can?: true, current_ability: current_ability, repository: repository, blacklight_config: blacklight_config, search_state_class: nil) } context 'when building a collection' do let(:coll123) do diff --git a/spec/search_builders/hyrax/admin_set_search_builder_spec.rb b/spec/search_builders/hyrax/admin_set_search_builder_spec.rb index 0b5ddd6723..1b4ba54cf6 100644 --- a/spec/search_builders/hyrax/admin_set_search_builder_spec.rb +++ b/spec/search_builders/hyrax/admin_set_search_builder_spec.rb @@ -2,7 +2,8 @@ RSpec.describe Hyrax::AdminSetSearchBuilder do let(:context) do double(blacklight_config: CatalogController.blacklight_config, - current_ability: ability) + current_ability: ability, + search_state_class: nil) end let(:ability) do ::Ability.new(user) diff --git a/spec/search_builders/hyrax/collection_member_search_builder_spec.rb b/spec/search_builders/hyrax/collection_member_search_builder_spec.rb index 1f6acfa8bd..2be97be2c0 100644 --- a/spec/search_builders/hyrax/collection_member_search_builder_spec.rb +++ b/spec/search_builders/hyrax/collection_member_search_builder_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Hyrax::CollectionMemberSearchBuilder do subject(:builder) { described_class.new(scope: context, collection: collection, search_includes_models: include_models) } - let(:context) { double("context", blacklight_config: CatalogController.blacklight_config) } + let(:context) { double("context", blacklight_config: CatalogController.blacklight_config, search_state_class: nil) } let(:solr_params) { { fq: [] } } let(:include_models) { :both } let(:collection) { build(:collection_lw, id: '12345') } diff --git a/spec/search_builders/hyrax/dashboard/collections_search_builder_spec.rb b/spec/search_builders/hyrax/dashboard/collections_search_builder_spec.rb index 1bdaf88a49..a430010788 100644 --- a/spec/search_builders/hyrax/dashboard/collections_search_builder_spec.rb +++ b/spec/search_builders/hyrax/dashboard/collections_search_builder_spec.rb @@ -3,7 +3,8 @@ let(:context) do double(blacklight_config: CatalogController.blacklight_config, current_ability: ability, - current_user: user) + current_user: user, + search_state_class: nil) end let(:ability) do ::Ability.new(user) diff --git a/spec/search_builders/hyrax/dashboard/nested_collections_search_builder_spec.rb b/spec/search_builders/hyrax/dashboard/nested_collections_search_builder_spec.rb index ec8881443c..7af25bbe0c 100644 --- a/spec/search_builders/hyrax/dashboard/nested_collections_search_builder_spec.rb +++ b/spec/search_builders/hyrax/dashboard/nested_collections_search_builder_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true RSpec.describe Hyrax::Dashboard::NestedCollectionsSearchBuilder do - let(:scope) { double(current_ability: ability, blacklight_config: CatalogController.blacklight_config) } + let(:scope) { double(current_ability: ability, blacklight_config: CatalogController.blacklight_config, search_state_class: nil) } let(:access) { :read } let(:user) { create(:user) } let(:ability) { ::Ability.new(user) } diff --git a/spec/search_builders/hyrax/dashboard/works_search_builder_spec.rb b/spec/search_builders/hyrax/dashboard/works_search_builder_spec.rb index 4cb86820e0..654e985e0a 100644 --- a/spec/search_builders/hyrax/dashboard/works_search_builder_spec.rb +++ b/spec/search_builders/hyrax/dashboard/works_search_builder_spec.rb @@ -3,7 +3,8 @@ let(:context) do double(blacklight_config: CatalogController.blacklight_config, current_ability: ability, - current_user: user) + current_user: user, + search_state_class: nil) end let(:ability) do ::Ability.new(user) diff --git a/spec/search_builders/hyrax/my/collections_search_builder_spec.rb b/spec/search_builders/hyrax/my/collections_search_builder_spec.rb index 04ac5334f9..796dc97683 100644 --- a/spec/search_builders/hyrax/my/collections_search_builder_spec.rb +++ b/spec/search_builders/hyrax/my/collections_search_builder_spec.rb @@ -3,7 +3,8 @@ let(:context) do double(blacklight_config: CatalogController.blacklight_config, current_ability: ability, - current_user: user) + current_user: user, + search_state_class: nil) end let(:ability) do ::Ability.new(user) diff --git a/spec/search_builders/hyrax/parent_collection_search_builder_spec.rb b/spec/search_builders/hyrax/parent_collection_search_builder_spec.rb index 8686acfb50..3f9b828dcf 100644 --- a/spec/search_builders/hyrax/parent_collection_search_builder_spec.rb +++ b/spec/search_builders/hyrax/parent_collection_search_builder_spec.rb @@ -3,7 +3,7 @@ let(:solr_params) { { fq: [] } } let(:item) { double(id: '12345', member_of_collection_ids: ['col1']) } let(:builder) { described_class.new(solr_params, context) } - let(:context) { double("context", blacklight_config: CatalogController.blacklight_config, item: item) } + let(:context) { double("context", blacklight_config: CatalogController.blacklight_config, item: item, search_state_class: nil) } describe '#include_item_ids' do let(:subject) { builder.include_item_ids(solr_params) } diff --git a/spec/search_builders/hyrax/single_admin_set_search_builder_spec.rb b/spec/search_builders/hyrax/single_admin_set_search_builder_spec.rb index baa698c2c5..a4fcabae30 100644 --- a/spec/search_builders/hyrax/single_admin_set_search_builder_spec.rb +++ b/spec/search_builders/hyrax/single_admin_set_search_builder_spec.rb @@ -3,7 +3,8 @@ let(:ability) { instance_double(Ability, admin?: true) } let(:context) do double(blacklight_config: CatalogController.blacklight_config, - current_ability: ability) + current_ability: ability, + search_state_class: nil) end let(:builder) { described_class.new(context) } diff --git a/spec/search_builders/hyrax/stats/work_status_search_builder_spec.rb b/spec/search_builders/hyrax/stats/work_status_search_builder_spec.rb index ee21302bbb..33f77b9d0d 100644 --- a/spec/search_builders/hyrax/stats/work_status_search_builder_spec.rb +++ b/spec/search_builders/hyrax/stats/work_status_search_builder_spec.rb @@ -4,7 +4,8 @@ let(:context) do double(blacklight_config: CatalogController.blacklight_config, - current_ability: ability) + current_ability: ability, + search_state_class: nil) end let(:ability) do diff --git a/spec/services/hyrax/admin_set_service_spec.rb b/spec/services/hyrax/admin_set_service_spec.rb index 530f5d4106..a4451f3526 100644 --- a/spec/services/hyrax/admin_set_service_spec.rb +++ b/spec/services/hyrax/admin_set_service_spec.rb @@ -4,7 +4,8 @@ let(:context) do double(current_ability: Ability.new(user), repository: controller.repository, - blacklight_config: controller.blacklight_config) + blacklight_config: controller.blacklight_config, + search_state_class: nil) end let(:service) { described_class.new(context) } let(:user) { create(:user) } diff --git a/spec/services/hyrax/collections/nested_collection_query_service_spec.rb b/spec/services/hyrax/collections/nested_collection_query_service_spec.rb index 6941dcc676..231cbc0120 100644 --- a/spec/services/hyrax/collections/nested_collection_query_service_spec.rb +++ b/spec/services/hyrax/collections/nested_collection_query_service_spec.rb @@ -5,7 +5,7 @@ let(:user) { create(:user) } let(:ability) { ::Ability.new(user) } let(:current_ability) { ability } - let(:scope) { double('Scope', can?: true, current_ability: current_ability, repository: repository, blacklight_config: blacklight_config) } + let(:scope) { double('Scope', can?: true, current_ability: current_ability, repository: repository, blacklight_config: blacklight_config, search_state_class: nil) } let(:collection_type) { create(:collection_type) } let(:another_collection_type) { create(:collection_type) } diff --git a/spec/support/fakes/fake_search_builder_scope.rb b/spec/support/fakes/fake_search_builder_scope.rb index 787784f2e2..a0fee84d68 100644 --- a/spec/support/fakes/fake_search_builder_scope.rb +++ b/spec/support/fakes/fake_search_builder_scope.rb @@ -10,6 +10,7 @@ # - +#current_user+ # - +#params+ # - +#repository+ +# - +#search_state_class+ # # This provides a fake scope with more control than a generic RSpec double. class FakeSearchBuilderScope @@ -24,17 +25,20 @@ class FakeSearchBuilderScope # @return [Hash] # @!attribute [r] repository # @return [Blacklight::AbstractRepository] - attr_reader :blacklight_config, :current_ability, :current_user, :params, :repository + # @!attribute [r] search_state_class + # @return [Blacklight::SearchState, nil] + attr_reader :blacklight_config, :current_ability, :current_user, :params, :repository, :search_state_class ## # @param [Blacklight::Configuration] blacklight_config # @param [::Ability, nil] current_ability # @param [::User, nil] current_user - def initialize(blacklight_config: CatalogController.blacklight_config, current_ability: nil, current_user: nil, params: {}) + def initialize(blacklight_config: CatalogController.blacklight_config, current_ability: nil, current_user: nil, params: {}, search_state_class: nil) @blacklight_config = blacklight_config @current_user = current_user @current_ability = current_ability || ::Ability.new(current_user) @params = params @repository = Blacklight::Solr::Repository.new(blacklight_config) + @search_state_class = search_state_class end end