Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show unavaliable pdfs #2805

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/assets/stylesheets/companion_window.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div data-controller="iiif-auth-restriction" data-action="<%= authorization_actions %>">
<%= render LoginComponent.new %>
<%= render LocationRestrictionComponent.new %>
<%= render CompanionWindows::ContentNotAvailableComponent.new unless available? %>
<%= render RestrictedMessageComponent.new %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/components/companion_windows/content_list_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions app/components/location_restriction_component.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/components/location_restriction_component.rb

This file was deleted.

20 changes: 9 additions & 11 deletions app/components/model_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
<div data-controller="locked-poster" data-action="auth-success@window->locked-poster#hide auth-denied@window->locked-poster#show" role="presentation" style="flex: 1 0 100%; text-align: center;" <%= 'hidden' if viewable_content? %>>
<div data-controller="locked-poster" data-action="auth-success@window->locked-poster#hide auth-denied@window->locked-poster#show" role="presentation" style="flex: 1 0 100%; text-align: center;" hidden>
<%= render LockedStatusComponent.new %>
</div>
<% if viewable_content? %>
<div class="sul-embed-3d sul-embed-body" data-action="iiif-manifest-received@window->file-auth#parseFiles">
<div class="buttons">
<button aria-label="Zoom in" class="zoom-in">+</button>
<button aria-label="Zoom out" class="zoom-out">-</button>
</div>
<div id="3d-viewer" class="model-viewer-container" data-controller="model" data-action="auth-success@window->model#show">
</div>
<div class="sul-embed-3d sul-embed-body" data-action="iiif-manifest-received@window->file-auth#parseFiles">
<div class="buttons">
<button aria-label="Zoom in" class="zoom-in">+</button>
<button aria-label="Zoom out" class="zoom-out">-</button>
</div>
<% end %>
<div id="3d-viewer" class="model-viewer-container" data-controller="model" data-action="auth-success@window->model#show">
</div>
</div>
<% end %>
<% end %>
4 changes: 0 additions & 4 deletions app/components/model_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 6 additions & 8 deletions app/components/pdf_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
<div data-controller="locked-poster" data-action="auth-success@window->locked-poster#hide auth-denied@window->locked-poster#show needs-login@window->locked-poster#show" role="presentation" style="flex: 1 0 100%; text-align: center;" <%= 'hidden' if viewer.available? %>>
<div data-controller="locked-poster" data-action="auth-success@window->locked-poster#hide auth-denied@window->locked-poster#show needs-login@window->locked-poster#show" role="presentation" style="flex: 1 0 100%; text-align: center;" hidden>
<%= render LockedStatusComponent.new %>
</div>
<div class="sul-embed-body" style="flex-basis: 100%">
<div style="display: flex; flex-direction: column; height: 100%">
<% if viewer.available? %>
<div class="sul-embed-pdf" style="height: 100%"
data-controller="pdf"
data-action="thumbnail-clicked@window->file-auth#authFileAndDisplay iiif-manifest-received@window->file-auth#parseFiles auth-success@window->pdf#show">
</div>
<% end %>
<div class="sul-embed-pdf" style="height: 100%"
data-controller="pdf"
data-action="thumbnail-clicked@window->file-auth#authFileAndDisplay iiif-manifest-received@window->file-auth#parseFiles auth-success@window->pdf#show">
</div>
</div>
</div>
<% end %>
Expand Down
4 changes: 4 additions & 0 deletions app/components/restricted_message_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="authLinkWrapper" data-iiif-auth-restriction-target="restrictedContainer" hidden>
<span class="icon" data-iiif-auth-restriction-target="restrictedIcon"></span>
<p class="loginMessage" data-iiif-auth-restriction-target="restrictedMessage"></p>
</div>
4 changes: 4 additions & 0 deletions app/components/restricted_message_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class RestrictedMessageComponent < ViewComponent::Base
end
15 changes: 3 additions & 12 deletions app/javascript/controllers/file_auth_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
}
}
13 changes: 7 additions & 6 deletions app/javascript/controllers/iiif_auth_restriction_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions app/viewers/embed/viewer/document_viewer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/components/pdf_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions spec/features/document_viewer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 0 additions & 44 deletions spec/lib/embed/viewer/document_viewer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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