-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HYC-1814 - Resolve rows not set warning from fileset pages (#1050)
* 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
Showing
1 changed file
with
10 additions
and
9 deletions.
There are no files selected for viewing
19 changes: 10 additions & 9 deletions
19
app/overrides/presenters/hyrax/file_set_presenter_override.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |