Skip to content

Commit

Permalink
🎁 Allowing per tenant ability to disable IIIF Print
Browse files Browse the repository at this point in the history
The current (as of <2023-08-10 Thu>) implementation of IIIF Print
assumes that we generate derivatives at the application level.  However,
we want options for generating at the tenant level.

As noted, I have chosen to default using IIIF print to `true` because
that was the behavior before this commit.

In other words, this commit is functionally a non-change to
the production code-base (assuming no one goes and flips some switches).

Related to:

- scientist-softserv/palni-palci#656
- scientist-softserv/palni-palci#657
- scientist-softserv/palni-palci#658
- scientist-softserv/palni-palci#659
  • Loading branch information
jeremyf committed Dec 15, 2023
1 parent 8d35b5d commit 5131093
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/forms/hyrax/image_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ImageForm < Hyrax::Forms::WorkForm
self.model_class = ::Image
include PdfFormBehavior

self.terms += %i[resource_type extent additional_information bibliographic_citation]
self.required_fields = %i[title creator keyword rights_statement resource_type]
self.terms += %i[extent additional_information bibliographic_citation]
self.required_fields = %i[title creator keyword rights_statement]
end
end
6 changes: 2 additions & 4 deletions app/services/iiif_print/tenant_config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

# rubocop:disable Metrics/LineLength
module IiifPrint
##
Expand Down Expand Up @@ -152,9 +150,9 @@ module WorkShowPresenterDecorator
# of files we want to consider for showing in the IIIF Viewer.
def iiif_media_predicates
if TenantConfig.use_iiif_print?
%i[image? audio? video? pdf?]
[:image?, :audio?, :video?, :pdf?]
else
%i[image? audio? video?]
[:image?, :audio?, :video?]
end
end

Expand Down
17 changes: 17 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class Application < Rails::Application
Object.include(AccountSwitch)
end

config.autoload_paths << "#{Rails.root}/app/controllers/api"

# copies tinymce assets directly into public/assets
config.tinymce.install = :copy
##
Expand All @@ -127,6 +129,21 @@ class Application < Rails::Application
User,
Time
]


##
# The first "#valid?" service is the one that we'll use for generating derivatives.
Hyrax::DerivativeService.services = [
IiifPrint::TenantConfig::DerivativeService,
Hyrax::FileSetDerivativesService
]

##
# This needs to be in the after initialize so that the IiifPrint gem can do it's decoration.
#
# @see https://github.com/scientist-softserv/iiif_print/blob/9e7837ce4bd08bf8fff9126455d0e0e2602f6018/lib/iiif_print/engine.rb#L54 Where we do the override.
Hyrax::Actors::FileSetActor.prepend(IiifPrint::TenantConfig::FileSetActorDecorator)
Hyrax::WorkShowPresenter.prepend(IiifPrint::TenantConfig::WorkShowPresenterDecorator)
end
end
end
1 change: 1 addition & 0 deletions config/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
feature :default_pdf_viewer,
default: true,
description: "Choose PDF.js or Universal Viewer to render PDFs. UV uses IIIF Print and requires PDF spltting with OCR. Switching from PDF.js to the UV may require re-ingesting of the PDF."

end
18 changes: 18 additions & 0 deletions spec/models/generic_work_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated via
# `rails generate hyrax:work GenericWork`
require 'rails_helper'
require 'order_already/spec_helper'

RSpec.describe GenericWork do
describe '#iiif_print_config#pdf_splitter_service' do
subject { described_class.new.iiif_print_config.pdf_splitter_service }

it { is_expected.to eq(IiifPrint::TenantConfig::PdfSplitter) }
end

describe "metadata" do
it { is_expected.to have_property(:bulkrax_identifier).with_predicate("https://hykucommons.org/terms/bulkrax_identifier") }
end

it { is_expected.to have_already_ordered_attributes(*described_class.multi_valued_properties_for_ordering) }
end
6 changes: 6 additions & 0 deletions spec/models/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
# `rails generate hyrax:work Image`

RSpec.describe Image do
describe '#iiif_print_config#pdf_splitter_service' do
subject { described_class.new.iiif_print_config.pdf_splitter_service }

it { is_expected.to eq(IiifPrint::TenantConfig::PdfSplitter) }
end

describe 'indexer' do
subject { described_class.indexer }

Expand Down
4 changes: 2 additions & 2 deletions spec/services/iiif_print/tenant_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ def initialize(file_set); end
context 'when the feature is flipped to false' do
before { test_strategy.switch!(:default_pdf_viewer, true) }

it { is_expected.to eq(%i[image? audio? video?]) }
it { is_expected.to eq([:image?, :audio?, :video?]) }
end

context 'when the feature is flipped to true' do
before { test_strategy.switch!(:default_pdf_viewer, false) }

it { is_expected.to eq(%i[image? audio? video? pdf?]) }
it { is_expected.to eq([:image?, :audio?, :video?, :pdf?]) }
end
end
end
Expand Down

0 comments on commit 5131093

Please sign in to comment.