Skip to content

Commit

Permalink
Merge pull request #5321 from avalonmediasystem/anno_service_declaration
Browse files Browse the repository at this point in the history
Add marker annotation service definition to playlist manifest if requested by playlist owner
  • Loading branch information
cjcolvar authored Aug 23, 2023
2 parents 5d208a3 + f815e62 commit d1dc1c7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/controllers/playlists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ def manifest
end
IiifPlaylistCanvasPresenter.new(playlist_item: item, stream_info: stream_info, cannot_read_item: cannot_read_item)
end
presenter = IiifPlaylistManifestPresenter.new(playlist: @playlist, items: canvas_presenters)

can_edit_playlist = can? :edit, @playlist
presenter = IiifPlaylistManifestPresenter.new(playlist: @playlist, items: canvas_presenters, can_edit_playlist: can_edit_playlist)
manifest = IIIFManifest::V3::ManifestFactory.new(presenter).to_h

respond_to do |wants|
Expand Down
15 changes: 13 additions & 2 deletions app/models/iiif_playlist_manifest_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ class IiifPlaylistManifestPresenter
IIIF_ALLOWED_TAGS = ['a', 'b', 'br', 'i', 'img', 'p', 'small', 'span', 'sub', 'sup'].freeze
IIIF_ALLOWED_ATTRIBUTES = ['href', 'src', 'alt'].freeze

attr_reader :playlist, :items
attr_reader :playlist, :items, :can_edit_playlist

def initialize(playlist:, items:)
def initialize(playlist:, items:, can_edit_playlist: false)
@playlist = playlist
@items = items
@can_edit_playlist = can_edit_playlist
end

def file_set_presenters
Expand Down Expand Up @@ -68,6 +69,16 @@ def manifest_metadata
@manifest_metadata ||= iiif_metadata_fields.compact
end

def service
return nil unless can_edit_playlist
[
{
id: Rails.application.routes.url_helpers.avalon_marker_index_url,
type: "AnnotationService0"
}
]
end

private

def sanitize(value)
Expand Down
20 changes: 20 additions & 0 deletions spec/controllers/playlists_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -576,5 +576,25 @@
expect(parsed_response['type']).to eq 'Manifest'
expect(parsed_response['items']).not_to be_empty
end

context "when playlist owner" do
before do
login_user playlist.user.user_key
end

it "includes the marker annotation service definition" do
get :manifest, format: 'json', params: { id: playlist.id }, session: valid_session
parsed_response = JSON.parse(response.body)
expect(parsed_response["service"]).to be_present
end
end

context "when not playlist owner" do
it "does not include the marker annotation service definition" do
get :manifest, format: 'json', params: { id: playlist.id }, session: valid_session
parsed_response = JSON.parse(response.body)
expect(parsed_response["service"]).not_to be_present
end
end
end
end

0 comments on commit d1dc1c7

Please sign in to comment.