Skip to content

Commit

Permalink
HYC-1814 - Resolve rows not set warning from fileset pages (#1050)
Browse files Browse the repository at this point in the history
* Set a rows param on file_set query to find parent work so that it won't generate warnings every time

* Sync file up with version merged into hyrax main
  • Loading branch information
bbpennel authored Nov 14, 2023
1 parent e9ea752 commit 7f7f985
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/overrides/presenters/hyrax/file_set_presenter_override.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# frozen_string_literal: true
# https://github.com/samvera/hyrax/blob/v3.4.2/app/presenters/hyrax/file_set_presenter.rb
# [hyc-override] https://github.com/samvera/hyrax/blob/hyrax-v4.0.0/app/presenters/hyrax/file_set_presenter.rb
Hyrax::FileSetPresenter.class_eval do
def fetch_parent_presenter
ids = Hyrax::SolrService.query("{!field f=member_ids_ssim}#{id}", fl: Hyrax.config.id_field)
ids = Hyrax::SolrService.query("{!field f=member_ids_ssim}#{id}", fl: Hyrax.config.id_field, rows: 1)
.map { |x| x.fetch(Hyrax.config.id_field) }
Hyrax.logger.warn("Couldn't find a parent work for FileSet: #{id}.") if ids.empty?
ids.each do |id|
doc = ::SolrDocument.find(id)
next if current_ability.can?(:edit, doc)
# [hyc-override] throw exception when suppressed if user CANNOT read the doc, rather than if they can
raise Hyrax::WorkflowAuthorizationException if doc.suppressed? && !current_ability.can?(:read, doc)
if ids.empty?
Hyrax.logger.warn("Couldn't find a parent work for FileSet: #{id}.")
else
doc = ::SolrDocument.find(ids.first)
unless current_ability.can?(:edit, doc)
# [hyc-override] throw exception when suppressed if user CANNOT read the doc, rather than if they can
raise Hyrax::WorkflowAuthorizationException if doc.suppressed? && !current_ability.can?(:read, doc)
end
end
Hyrax::PresenterFactory.build_for(ids: ids,
presenter_class: Hyrax::WorkShowPresenter,
presenter_args: current_ability).first

end
end

0 comments on commit 7f7f985

Please sign in to comment.