use correct content disposition for local files

pull/7456/head
Markus Kahl 5 years ago
parent 6f287a512a
commit 4cc4730bcd
  1. 2
      lib/api/helpers/attachment_renderer.rb
  2. 22
      spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb

@ -44,7 +44,7 @@ module API
redirect attachment.external_url.to_s
else
content_type attachment.content_type
header['Content-Disposition'] = "attachment; filename=#{attachment.filename}"
header['Content-Disposition'] = attachment.content_disposition
env['api.format'] = :binary
attachment.diskfile.read
end

@ -252,8 +252,10 @@ shared_examples 'an APIv3 attachment resource', type: :request, content_type: :j
subject(:response) { last_response }
context 'with required permissions' do
context 'for a local file' do
let(:mock_file) { FileHelpers.mock_uploaded_file name: 'foobar.txt' }
shared_examples 'for a local file' do
let(:mock_file) { raise "define mock_file" }
let(:content_disposition) { raise "define content_disposition" }
let(:attachment) do
att = FactoryBot.create(:attachment, container: container, file: mock_file)
@ -270,7 +272,7 @@ shared_examples 'an APIv3 attachment resource', type: :request, content_type: :j
it 'has the necessary headers' do
expect(subject.headers['Content-Disposition'])
.to eql "attachment; filename=#{mock_file.original_filename}"
.to eql content_disposition
expect(subject.headers['Content-Type'])
.to eql mock_file.content_type
@ -282,6 +284,20 @@ shared_examples 'an APIv3 attachment resource', type: :request, content_type: :j
end
end
context 'for a local text file' do
it_behaves_like 'for a local file' do
let(:mock_file) { FileHelpers.mock_uploaded_file name: 'foobar.txt' }
let(:content_disposition) { "inline" }
end
end
context 'for a local binary file' do
it_behaves_like 'for a local file' do
let(:mock_file) { FileHelpers.mock_uploaded_file name: 'foobar.dat', content_type: "application/octet-stream" }
let(:content_disposition) { "attachment; filename=#{mock_file.original_filename}" }
end
end
context 'for a remote file' do
let(:external_url) { 'http://some_service.org/blubs.gif' }
let(:mock_file) { FileHelpers.mock_uploaded_file name: 'foobar.txt' }

Loading…
Cancel
Save