Skip to content

Commit

Permalink
Merge pull request #559 from IU-Libraries-Joint-Development/essi-1435…
Browse files Browse the repository at this point in the history
…_pdf_download_redirect

[ESSI-1435] fix failing unauthorized pdf download redirect
  • Loading branch information
randalldfloyd authored Aug 4, 2023
2 parents c312a50 + cd15c8e commit 8636732
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/concerns/essi/pdf_download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def pdf
type: 'application/pdf',
disposition: 'inline'
else
redirect_to [main_app, curation_concern],
redirect_to [main_app, presenter],
alert: 'You do not have access to download this PDF.'
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
Hyrax::ArchivalMaterialPresenter,
described_class)
include_examples('update metadata remotely', :archival_material)
include_examples('pdf controller actions', :archival_material)
end
1 change: 1 addition & 0 deletions spec/controllers/hyrax/paged_resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
Hyrax::PagedResourcePresenter,
described_class)
include_examples('update metadata remotely', :paged_resource)
include_examples('pdf controller actions', :paged_resource)
end
23 changes: 23 additions & 0 deletions spec/support/shared_examples/pdf_controller_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RSpec.shared_examples 'pdf controller actions' do |resource_symbol|

describe 'when logged in', :clean do
let(:main_app) { Rails.application.routes.url_helpers }
let(:user) { FactoryBot.create(:user) }
let(:resource) { FactoryBot.create(resource_symbol, user: user, title: ['Dummy Title'], pdf_state: 'NOT downloadable') }

describe '#pdf' do
context 'without authorization' do
before(:each) do
get :pdf, params: { id: resource.id }
end
it 'redirects to the resource' do
show_page = main_app.send("hyrax_#{resource_symbol}_path", resource, locale: 'en')
expect(response).to redirect_to show_page
end
it 'displays an alert' do
expect(flash[:alert]).to match /You do not have access to download this PDF/i
end
end
end
end
end

0 comments on commit 8636732

Please sign in to comment.