Skip to content

Commit

Permalink
Adjust error when trying to download a work so that an Auth exception…
Browse files Browse the repository at this point in the history
… occurs instead of a 500 error (#1121)
  • Loading branch information
bbpennel authored Oct 3, 2024
1 parent a043630 commit af2bb8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app/overrides/controllers/hyrax/downloads_controller_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ def set_record_admin_set

private

# This is unmodified from hyrax
def file_set_parent(file_set_id)
file_set = Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: file_set_id, use_valkyrie: Hyrax.config.use_valkyrie?)
file_set = if defined?(Wings) && Hyrax.metadata_adapter.is_a?(Wings::Valkyrie::MetadataAdapter)
Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: file_set_id, use_valkyrie: Hyrax.config.use_valkyrie?)
else
Hyrax.query_service.find_by(id: file_set_id)
end
@parent ||=
case file_set
when Hyrax::Resource
Hyrax.query_service.find_parents(resource: file_set).first
else
file_set.parent
# [hyc-override] If the object doesn't support parent, then throw an expected error
if file_set.respond_to?(:parent)
file_set.parent
else
raise Hyrax::WorkflowAuthorizationException
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/hyrax/downloads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@
expect(response.headers['Content-Disposition']).to include 'filename="no_extension"'
end
end

context 'with work' do
let(:work) { Article.create(title: ['New Article']) }

it 'will deny permission if trying to download the work' do
allow(subject).to receive(:authorize!)
get :show, params: { id: work.id}
expect(response).to be_unauthorized
end
end
end

end

0 comments on commit af2bb8d

Please sign in to comment.