Skip to content

Commit

Permalink
Merge pull request #3739 from mlibrary/HELIO-4278/exclude_expiration_…
Browse files Browse the repository at this point in the history
…date_tombstones_from_prev_next

HELIO-4278 - no prev/next to expired permission resources
  • Loading branch information
sethaj authored Jan 29, 2025
2 parents 434bbe1 + ef2051b commit 5c1895b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
18 changes: 12 additions & 6 deletions app/presenters/hyrax/file_set_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ def subjects
parent.subject
end

# If a user can load the current FileSet in draft mode then they should be able to get to draft siblings...
# using prev/next. Examples are logged-in admins/editors or authors using a share link to view a draft book.
# representatives/covers and tombstones should never appear in prev/next.
def prev_next_shared_clauses
"+monograph_id_ssim:#{monograph_id} AND -hidden_representative_bsi:true AND -tombstone_ssim:yes AND -permissions_expiration_date_ssim:[* TO #{Time.zone.today.strftime('%Y-%m-%d')}]"
end

# A user who can load the stats dashboard has a role of analyst or above, and so should be able to get to draft...
# siblings using prev/next. Authors using a share link to view a draft book should also be able to do this, but...
# anonymous users should not.
def prev_next_visibility_clause
if visibility == 'restricted'
if @valid_share_link || current_ability.can?(:read, :stats_dashboard)
nil
else
'AND -visibility_ssi:restricted '
Expand All @@ -85,8 +91,8 @@ def previous_id
@previous_id = if solr_document['monograph_position_isi'] == 0
nil
else
# representatives/covers and tombstones should never appear in prev/next. See above RE: prev_next_visibility_clause
ActiveFedora::SolrService.query("+monograph_id_ssim:#{monograph_id} AND -hidden_representative_bsi:true AND -tombstone_ssim:yes #{prev_next_visibility_clause}AND monograph_position_isi:[* TO #{solr_document['monograph_position_isi'] - 1}]",

ActiveFedora::SolrService.query("#{prev_next_shared_clauses} #{prev_next_visibility_clause}AND monograph_position_isi:[* TO #{solr_document['monograph_position_isi'] - 1}]",
sort: 'monograph_position_isi desc',
rows: 1)&.first&.id
end
Expand All @@ -99,7 +105,7 @@ def next_id?
def next_id
return @next_id if @next_id.present?

@next_id = ActiveFedora::SolrService.query("+monograph_id_ssim:#{monograph_id} AND -hidden_representative_bsi:true AND -tombstone_ssim:yes #{prev_next_visibility_clause}AND monograph_position_isi:[#{solr_document['monograph_position_isi'] + 1} TO *]",
@next_id = ActiveFedora::SolrService.query("#{prev_next_shared_clauses} #{prev_next_visibility_clause}AND monograph_position_isi:[#{solr_document['monograph_position_isi'] + 1} TO *]",
sort: 'monograph_position_isi asc',
rows: 1)&.first&.id
end
Expand Down
26 changes: 25 additions & 1 deletion spec/features/show_file_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

monograph.ordered_members << FactoryBot.create(:file_set) << FactoryBot.create(:public_file_set)
monograph.ordered_members << tombstoned_file_set << epub << FactoryBot.create(:public_file_set)
monograph.ordered_members << FactoryBot.create(:public_file_set, permissions_expiration_date: '2025-01-01')
monograph.ordered_members << FactoryBot.create(:public_file_set)

monograph.save!
FileSet.all.each(&:save!)
Expand Down Expand Up @@ -63,7 +65,7 @@
# no next link to the tombstone or EPUB representative...
expect(page).to_not have_link('Next', href: monograph.ordered_members.to_a[6].id)
expect(page).to_not have_link('Next', href: monograph.ordered_members.to_a[7].id)
# ... instead the next link goes to the final published resource
# ... instead the next link goes to the published resource after that
expect(page).to have_link('Next', href: monograph.ordered_members.to_a[8].id)

visit hyrax_file_set_path(monograph.ordered_members.to_a[8].id)
Expand All @@ -72,6 +74,16 @@
expect(page).not_to have_link('Previous', href: monograph.ordered_members.to_a[6].id)
# ... instead the previous link goes to the previous published resource
expect(page).to have_link('Previous', href: monograph.ordered_members.to_a[5].id)
# no next link to the FileSet that's tombstoned by being past its "Permissions Expiration Date"...
expect(page).not_to have_link('Next', href: monograph.ordered_members.to_a[9].id)
# ... instead the next link goes to the published resource after that
expect(page).to have_link('Next', href: monograph.ordered_members.to_a[10].id)

visit hyrax_file_set_path(monograph.ordered_members.to_a[10].id)
# no previous link to the FileSet that's tombstoned by being past its "Permissions Expiration Date"...
expect(page).not_to have_link('Previous', href: monograph.ordered_members.to_a[9].id)
# ... instead the previous link goes to the previous published resource
expect(page).to have_link('Previous', href: monograph.ordered_members.to_a[8].id)
# no next link at all, this is the end of the chain
expect(page).to_not have_link('Next')
end
Expand All @@ -97,6 +109,8 @@
end

monograph.ordered_members << tombstoned_file_set << epub << FactoryBot.create(:file_set)
monograph.ordered_members << FactoryBot.create(:public_file_set, permissions_expiration_date: '2025-01-01')
monograph.ordered_members << FactoryBot.create(:public_file_set)

monograph.save!
FileSet.all.each(&:save!)
Expand Down Expand Up @@ -147,6 +161,16 @@
expect(page).not_to have_link('Previous', href: monograph.ordered_members.to_a[6].id)
# ... instead the previous link goes to the previous published resource
expect(page).to have_link('Previous', href: monograph.ordered_members.to_a[5].id)
# no next link to the FileSet that's tombstoned by being past its "Permissions Expiration Date"...
expect(page).not_to have_link('Next', href: monograph.ordered_members.to_a[9].id)
# ... instead the next link goes to the published resource after that
expect(page).to have_link('Next', href: monograph.ordered_members.to_a[10].id)

visit hyrax_file_set_path(monograph.ordered_members.to_a[10].id)
# no previous link to the FileSet that's tombstoned by being past its "Permissions Expiration Date"...
expect(page).not_to have_link('Previous', href: monograph.ordered_members.to_a[9].id)
# ... instead the previous link goes to the previous published resource
expect(page).to have_link('Previous', href: monograph.ordered_members.to_a[8].id)
# no next link at all, this is the end of the chain
expect(page).to_not have_link('Next')
end
Expand Down

0 comments on commit 5c1895b

Please sign in to comment.