diff --git a/app/presenters/hyrax/collection_presenter_decorator.rb b/app/presenters/hyrax/collection_presenter_decorator.rb index c348e5888..1adb737b1 100644 --- a/app/presenters/hyrax/collection_presenter_decorator.rb +++ b/app/presenters/hyrax/collection_presenter_decorator.rb @@ -96,6 +96,25 @@ def collection_featurable? user_can_feature_collection? && solr_document.public? end + ## + # OVERRIDE to handle search_only tenant's not having access to the collection type badge from + # the document's home tenant. + # + # @return [String] + # + # @see https://github.com/scientist-softserv/palni-palci/issues/951 + # @see https://github.com/samvera/hyku/issues/1815 + def collection_type_badge + return "" unless Site.account&.present? + return "" if Site.account.search_only? + + super + rescue ActiveRecord::RecordNotFound + # This is a fail-safe if we deleted the underlying Hyrax::CollectionType but have not yet + # cleaned up the SOLR records. + "" + end + def display_feature_collection_link? collection_featurable? && FeaturedCollection.can_create_another? && !collection_featured? end diff --git a/spec/presenters/hyrax/collection_presenter_decorator_spec.rb b/spec/presenters/hyrax/collection_presenter_decorator_spec.rb new file mode 100644 index 000000000..d5c795cbd --- /dev/null +++ b/spec/presenters/hyrax/collection_presenter_decorator_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Hyrax::CollectionPresenter do + describe '#collection_type_badge' do + subject { presenter.collection_type_badge } + + # We're decorating an alternate base class so that we don't need the full pre-amble for testing + # our decoration. In other words, let's trust Hyrax::CollectionPresenter's specs for the + # "super" method call. + let(:base_class) do + Class.new do + def collection_type_badge + "" + end + prepend Hyrax::CollectionPresenterDecorator + end + end + let(:presenter) { base_class.new } + + before { allow(Site).to receive(:account).and_return(account) } + + context 'when the Site.account is nil' do + let(:account) { nil } + + it { is_expected.to eq("") } + end + + context 'when the Site.account is search_only' do + let(:account) { FactoryBot.build(:account, search_only: true) } + + it { is_expected.to eq("") } + end + + context 'when the Site.account is NOT search_only' do + let(:account) { FactoryBot.build(:account, search_only: false) } + + it { is_expected.to start_with("