diff --git a/app/assets/stylesheets/companion_window.css b/app/assets/stylesheets/companion_window.css index ff560da9a..e8514b754 100644 --- a/app/assets/stylesheets/companion_window.css +++ b/app/assets/stylesheets/companion_window.css @@ -338,20 +338,26 @@ body { .vert-tabs, .left-drawer, .modal-components-popover, + .authLinkWrapper span, .authLinkWrapper, .sul-embed-geo-sidebar-header, .copy-to-clipboard, .sul-embed-was-seed-list-item { + --display: inline-block; svg { fill: currentColor; width: 1em; height: 1em; - display: inline-block; + display: var(--display); font-size: 1.5rem; flex-shrink: 0; } } + .authLinkWrapper span { + --display: block; + } + .companion-window-component-body { display: flex; flex-grow: 1; diff --git a/app/components/companion_windows/authorization_messages_component.html.erb b/app/components/companion_windows/authorization_messages_component.html.erb index 334f97afb..2e28a8a78 100644 --- a/app/components/companion_windows/authorization_messages_component.html.erb +++ b/app/components/companion_windows/authorization_messages_component.html.erb @@ -1,5 +1,4 @@
<%= render LoginComponent.new %> - <%= render LocationRestrictionComponent.new %> - <%= render CompanionWindows::ContentNotAvailableComponent.new unless available? %> + <%= render RestrictedMessageComponent.new %>
diff --git a/app/components/companion_windows/authorization_messages_component.rb b/app/components/companion_windows/authorization_messages_component.rb index e7e8a1372..40e589783 100644 --- a/app/components/companion_windows/authorization_messages_component.rb +++ b/app/components/companion_windows/authorization_messages_component.rb @@ -2,14 +2,6 @@ module CompanionWindows class AuthorizationMessagesComponent < ViewComponent::Base - def initialize(available:) - @available = available - end - - def available? - @available - end - # bindings to stimulus actions def authorization_actions %w[auth-denied@window->iiif-auth-restriction#displayMessage diff --git a/app/components/companion_windows/content_list_component.rb b/app/components/companion_windows/content_list_component.rb index 28e1a7e23..0ad096681 100644 --- a/app/components/companion_windows/content_list_component.rb +++ b/app/components/companion_windows/content_list_component.rb @@ -13,7 +13,7 @@ def document_viewer? end def resource_files_collection - viewer.purl_object.resource_files.reject(&:no_download?) + viewer.purl_object.resource_files end end end diff --git a/app/components/location_restriction_component.html.erb b/app/components/location_restriction_component.html.erb deleted file mode 100644 index c91ee30b8..000000000 --- a/app/components/location_restriction_component.html.erb +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/app/components/location_restriction_component.rb b/app/components/location_restriction_component.rb deleted file mode 100644 index da6e7e2fd..000000000 --- a/app/components/location_restriction_component.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -# This is only used by the PdfComponent -class LocationRestrictionComponent < ViewComponent::Base -end diff --git a/app/components/model_component.html.erb b/app/components/model_component.html.erb index 1b7ef1220..3e869f960 100644 --- a/app/components/model_component.html.erb +++ b/app/components/model_component.html.erb @@ -8,22 +8,20 @@ <% end %> <% component.with_authorization_messages do %> - <%= render CompanionWindows::AuthorizationMessagesComponent.new(available: viewable_content?) %> + <%= render CompanionWindows::AuthorizationMessagesComponent.new %> <% end %> <% component.with_body do %> -
> + - <% if viewable_content? %> -
-
- - -
-
-
+
+
+ +
- <% end %> +
+
+
<% end %> <% end %> diff --git a/app/components/model_component.rb b/app/components/model_component.rb index 7b5bd9fca..ea251cd24 100644 --- a/app/components/model_component.rb +++ b/app/components/model_component.rb @@ -8,8 +8,4 @@ def initialize(viewer:) attr_reader :viewer delegate :purl_object, to: :viewer - - def viewable_content? - viewer.three_dimensional_files.any? - end end diff --git a/app/components/pdf_component.html.erb b/app/components/pdf_component.html.erb index 93eaa0f22..ce722ff5a 100644 --- a/app/components/pdf_component.html.erb +++ b/app/components/pdf_component.html.erb @@ -8,21 +8,19 @@ <% end %> <% component.with_authorization_messages do %> - <%= render CompanionWindows::AuthorizationMessagesComponent.new(available: viewer.available?) %> + <%= render CompanionWindows::AuthorizationMessagesComponent.new %> <% end %> <% component.with_body do %> -
> +
- <% if viewer.available? %> -
-
- <% end %> +
+
<% end %> diff --git a/app/components/restricted_message_component.html.erb b/app/components/restricted_message_component.html.erb new file mode 100644 index 000000000..fa4600fe8 --- /dev/null +++ b/app/components/restricted_message_component.html.erb @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/app/components/restricted_message_component.rb b/app/components/restricted_message_component.rb new file mode 100644 index 000000000..374d7c9e3 --- /dev/null +++ b/app/components/restricted_message_component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class RestrictedMessageComponent < ViewComponent::Base +end diff --git a/app/javascript/controllers/file_auth_controller.js b/app/javascript/controllers/file_auth_controller.js index ca2be4247..b85b113e4 100644 --- a/app/javascript/controllers/file_auth_controller.js +++ b/app/javascript/controllers/file_auth_controller.js @@ -136,10 +136,9 @@ export default class extends Controller { .then((result) => this.renderViewer(result)) .catch((authResponse) => { - // Intercept the response and check for location restriction before trying to log in, because - // logging in won't help the fact that we're not in an authorized location. - if (this.isLocationRestricted(authResponse)) - return this.authDenied(authResponse, accessService) + // Intercept the response and check for files that can't be accessed before trying to log in, because + // logging in won't help the fact that we're not in an authorized location/file is no download/embargoed (without stanford login). + if (authResponse.status == '403') return this.authDenied(authResponse, accessService) // Check if non-expired token already exists in local storage, // and if it exists, query probe service with it @@ -258,12 +257,4 @@ export default class extends Controller { const event = new CustomEvent('auth-denied', { detail: { accessService, authResponse } } ) window.dispatchEvent(event) } - - // Checks the result of the probe auth request to see if access is restricted to location - // This code depends on the text returned by probe service, so changes to the heading - // should be reflected here as well. - isLocationRestricted(json) { - return json.status == '401' && 'heading' in json && 'en' in json.heading && json.heading.en.length - && json.heading.en[0].startsWith('Access is restricted to the') - } } diff --git a/app/javascript/controllers/iiif_auth_restriction_controller.js b/app/javascript/controllers/iiif_auth_restriction_controller.js index b3f67cc0c..be9f2477d 100644 --- a/app/javascript/controllers/iiif_auth_restriction_controller.js +++ b/app/javascript/controllers/iiif_auth_restriction_controller.js @@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus" // Display auth controls for the file_auth_controller.js export default class extends Controller { - static targets = ["locationRestriction", "locationRestrictionMessage", "messagePanel", "loginPanel", + static targets = ["restrictedContainer", "restrictedMessage", "restrictedIcon", "messagePanel", "loginPanel", "loginButton", "loginMessage"] // Bound to auth-denied CustomEvents @@ -11,20 +11,21 @@ export default class extends Controller { this.resetMessages() const detail = event.detail - this.locationRestrictionTarget.hidden = false - this.locationRestrictionMessageTarget.innerHTML = this.#retrieveAuthResponseMessage(detail.authResponse) + this.restrictedContainerTarget.hidden = false + this.restrictedMessageTarget.innerHTML = this.#retrieveAuthResponseMessage(detail.authResponse) + this.restrictedIconTarget.innerHTML = detail.authResponse['icon'] } resetMessages() { this.hideLoginPrompt() this.hideMessagePanel() - this.clearLocationRestriction() + this.clearRestrictedMessage() } // Called when switching to a new file - clearLocationRestriction() { - this.locationRestrictionTarget.hidden = true + clearRestrictedMessage() { + this.restrictedContainerTarget.hidden = true } // Allow the user to dismiss the message diff --git a/app/viewers/embed/viewer/document_viewer.rb b/app/viewers/embed/viewer/document_viewer.rb index da4409068..649373f62 100644 --- a/app/viewers/embed/viewer/document_viewer.rb +++ b/app/viewers/embed/viewer/document_viewer.rb @@ -27,13 +27,6 @@ def fullscreen? true end - # This indicates if the first PDF is downloadable (though it could be stanford only) - # as well as location restricted. Authorization for other documents will be - # checked as the user clicks on items in the content side bar. - def available? - !document_resource_files.first&.no_download? - end - private def document_resource_files diff --git a/spec/components/companion_windows/content_list_component_spec.rb b/spec/components/companion_windows/content_list_component_spec.rb index 7d77ab3e4..decf2fbb2 100644 --- a/spec/components/companion_windows/content_list_component_spec.rb +++ b/spec/components/companion_windows/content_list_component_spec.rb @@ -40,8 +40,8 @@ end describe '#resource_files_collection' do - it 'returns a list of all purl objects that do not have no_download? returning true' do - expect(component.resource_files_collection).to eq([download_file]) + it 'returns a list of all purl objects' do + expect(component.resource_files_collection).to eq([no_download_file, download_file]) end end end diff --git a/spec/components/pdf_component_spec.rb b/spec/components/pdf_component_spec.rb index 494921da6..58c3fd8b9 100644 --- a/spec/components/pdf_component_spec.rb +++ b/spec/components/pdf_component_spec.rb @@ -26,7 +26,7 @@ end it 'includes access restriction method section' do - expect(page).to have_css('div[data-iiif-auth-restriction-target="locationRestriction"]', visible: :all) + expect(page).to have_css('div[data-iiif-auth-restriction-target="restrictedContainer"]', visible: :all) end context 'when hide_title is passed' do diff --git a/spec/components/location_restriction_component_spec.rb b/spec/components/restricted_message_component_spec.rb similarity index 74% rename from spec/components/location_restriction_component_spec.rb rename to spec/components/restricted_message_component_spec.rb index a1df3bac7..e04e961bc 100644 --- a/spec/components/location_restriction_component_spec.rb +++ b/spec/components/restricted_message_component_spec.rb @@ -2,17 +2,17 @@ require 'rails_helper' -RSpec.describe LocationRestrictionComponent, type: :component do +RSpec.describe RestrictedMessageComponent, type: :component do before do render_inline(described_class.new) end # The location restriction banner is hidden so search with visible: :all it 'renders banner target for the file auth controller' do - expect(page).to have_css('div[data-iiif-auth-restriction-target="locationRestriction"]', visible: :all) + expect(page).to have_css('div[data-iiif-auth-restriction-target="restrictedContainer"]', visible: :all) end it 'renders message target for the file auth controller' do - expect(page).to have_css('p[data-iiif-auth-restriction-target="locationRestrictionMessage"]', visible: :all) + expect(page).to have_css('p[data-iiif-auth-restriction-target="restrictedMessage"]', visible: :all) end end diff --git a/spec/features/document_viewer_spec.rb b/spec/features/document_viewer_spec.rb index 78ed97a19..c5de414d6 100644 --- a/spec/features/document_viewer_spec.rb +++ b/spec/features/document_viewer_spec.rb @@ -15,12 +15,4 @@ expect(page).to have_css('.sul-embed-pdf') end end - - context 'when no download' do - let(:purl) { build(:purl, :document_no_download) } - - it 'renders the PDF viewer for documents with restriction message' do - expect(page).to have_content('This item cannot be accessed online') - end - end end diff --git a/spec/lib/embed/viewer/document_viewer_spec.rb b/spec/lib/embed/viewer/document_viewer_spec.rb index 94303fd5e..432833889 100644 --- a/spec/lib/embed/viewer/document_viewer_spec.rb +++ b/spec/lib/embed/viewer/document_viewer_spec.rb @@ -32,48 +32,4 @@ expect(pdf_viewer.pdf_files.last).to match(%r{/file/druid:abc123/doc-xyz321\.pdf}) end end - - describe '#available?' do - context 'when the first file in the documents is location restricted and downloadable' do - let(:purl) do - instance_double( - Embed::Purl, - contents: [ - instance_double(Embed::Purl::Resource, type: 'document', files: [instance_double(Embed::Purl::ResourceFile, title: 'doc-abc123.pdf', location_restricted?: true, no_download?: false)]) - ], - druid: 'abc123' - ) - end - - it { expect(pdf_viewer.available?).to be true } - end - - context 'when the first file in the document is not location restricted and downloadable' do - let(:purl) do - instance_double( - Embed::Purl, - contents: [ - instance_double(Embed::Purl::Resource, type: 'document', files: [instance_double(Embed::Purl::ResourceFile, title: 'doc-abc123.pdf', location_restricted?: false, no_download?: false)]) - ], - druid: 'abc123' - ) - end - - it { expect(pdf_viewer.available?).to be true } - end - - context 'when the first file in the document is not downloadable' do - let(:purl) do - instance_double( - Embed::Purl, - contents: [ - instance_double(Embed::Purl::Resource, type: 'document', files: [instance_double(Embed::Purl::ResourceFile, title: 'doc-abc123.pdf', location_restricted?: false, no_download?: true)]) - ], - druid: 'abc123' - ) - end - - it { expect(pdf_viewer.available?).to be false } - end - end end