Skip to content

Commit

Permalink
HYC-2012 - Fix default thumbs and fallback during unlinking (#1144)
Browse files Browse the repository at this point in the history
* Fall back to next fileset in work when unlinking, so that the indexed work will still have a thumbnail

* Remove thumbnail presenter overrides
  • Loading branch information
bbpennel authored Feb 11, 2025
1 parent 29c7e26 commit 4d093f4
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 148 deletions.
18 changes: 18 additions & 0 deletions app/overrides/actors/hyrax/actors/file_set_actor_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,22 @@
def update_content(file, relation = :original_file)
IngestJob.perform_now(wrapper!(file: file, relation: relation), notification: true)
end

# [hyc-override] Fall back to the next fileset for thumbnail/represenatative if there are any remaining in the work
def unlink_from_work
work = parent_for(file_set: file_set)
return unless work && (work.thumbnail_id == file_set.id || work.representative_id == file_set.id || work.rendering_ids.include?(file_set.id))

remaining_members = work.members.to_a.reject { |member| member.id == file_set.id }
if remaining_members.empty?
work.thumbnail = nil
work.representative = nil
else
work.thumbnail = remaining_members.first
work.representative = remaining_members.first
end

work.rendering_ids -= [file_set.id]
work.save!
end
end

This file was deleted.

21 changes: 0 additions & 21 deletions app/overrides/presenters/hyrax/work_show_presenter_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,4 @@
def scholarly?
false
end

def fetch_primary_fileset_id
res = representative_id.blank? ? member_ids.first : representative_id
res
end

# [hyc-override] Use a work's first related fileset_id instead of the representative_id if it's nil
# @return FileSetPresenter presenter for the representative FileSets
def representative_presenter
@representative_presenter ||=
begin
primary_fileset_id = fetch_primary_fileset_id
return nil if primary_fileset_id.blank?
result = member_presenters([primary_fileset_id]).first
return nil if result.try(:id) == id
result.try(:representative_presenter) || result
rescue Hyrax::ObjectNotFoundError
Hyrax.logger.warn "Unable to find representative_id #{primary_fileset_id} for work #{id}"
return nil
end
end
end
12 changes: 0 additions & 12 deletions app/views/hyrax/base/_representative_media.html.erb

This file was deleted.

48 changes: 48 additions & 0 deletions spec/actors/hyrax/actors/file_set_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,52 @@
expect(actor.update_content(file)).to be_a(IngestJob)
end
end

describe '#unlink_from_work' do
let(:work) { FactoryBot.create(:work) }

context 'work with one file' do
before do
actor.attach_to_work(work)
work.rendering_ids = [file_set.id]
work.save!
end

it 'removes file_set from work' do
expect(work.thumbnail_id).to eq(file_set.id)
expect(work.representative_id).to eq(file_set.id)
expect(work.rendering_ids).to eq([file_set.id])

actor.unlink_from_work
work.reload
expect(work.thumbnail_id).to be_nil
expect(work.representative_id).to be_nil
expect(work.rendering_ids).to be_empty
end
end

context 'work with two files' do
let(:file_set2) { FactoryBot.create(:file_set) }
let(:actor2) { described_class.new(file_set2, user) }

before do
actor.attach_to_work(work)
actor2.attach_to_work(work)
work.rendering_ids = [file_set.id, file_set2.id]
work.save!
end

it 'removes file_set from work' do
expect(work.thumbnail_id).to eq(file_set.id)
expect(work.representative_id).to eq(file_set.id)
expect(work.rendering_ids).to eq([file_set.id, file_set2.id])

actor.unlink_from_work
work.reload
expect(work.thumbnail_id).to eq(file_set2.id)
expect(work.representative_id).to eq(file_set2.id)
expect(work.rendering_ids).to eq([file_set2.id])
end
end
end
end
51 changes: 0 additions & 51 deletions spec/presenters/blacklight/thumbnail_presenter_spec.rb

This file was deleted.

16 changes: 0 additions & 16 deletions spec/presenters/hyrax/work_show_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,4 @@
it { is_expected.to delegate_method(:resource_type).to(:solr_document) }
it { is_expected.to delegate_method(:keyword).to(:solr_document) }
it { is_expected.to delegate_method(:itemtype).to(:solr_document) }

describe '#representative_presenter' do
context 'when member_presenters raises a Hyrax::ObjectNotFoundError' do
before do
allow(presenter).to receive(:fetch_primary_fileset_id).and_return('file_set_id_1')
allow(presenter).to receive(:member_presenters).and_raise(Hyrax::ObjectNotFoundError)
allow(Hyrax.logger).to receive(:warn)
end

it 'logs a warning and returns nil' do
result = presenter.representative_presenter
expect(Hyrax.logger).to have_received(:warn).with('Unable to find representative_id file_set_id_1 for work 888888')
expect(result).to be_nil
end
end
end
end

0 comments on commit 4d093f4

Please sign in to comment.