Feature #43484 » 0006-Send-an-attachment-inline-based-on-its-detected-cont.patch
| app/controllers/attachments_controller.rb | ||
|---|---|---|
| 79 | 79 |
end |
| 80 | 80 | |
| 81 | 81 |
if stale?(:etag => @attachment.digest, :template => false) |
| 82 |
# images are sent inline
|
|
| 82 |
# PDFs are sent inline
|
|
| 83 | 83 |
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), |
| 84 | 84 |
:type => detect_content_type(@attachment), |
| 85 | 85 |
:disposition => disposition(@attachment) |
| ... | ... | |
| 310 | 310 |
end |
| 311 | 311 | |
| 312 | 312 |
def disposition(attachment) |
| 313 |
if attachment.is_pdf?
|
|
| 313 |
if detect_content_type(attachment) == 'application/pdf'
|
|
| 314 | 314 |
'inline' |
| 315 | 315 |
else |
| 316 | 316 |
'attachment' |
| test/functional/attachments_controller_test.rb | ||
|---|---|---|
| 391 | 391 |
assert_equal 'text/javascript', @response.media_type |
| 392 | 392 |
end |
| 393 | 393 | |
| 394 |
def test_download_should_not_send_a_non_pdf_file_inline_even_with_a_pdf_extension |
|
| 395 |
set_tmp_attachments_directory |
|
| 396 |
attachment = Attachment.create!( |
|
| 397 |
:file => mock_file_with_options(:original_filename => 'fake.pdf', |
|
| 398 |
:content => '<html><body>Hello</body></html>'), |
|
| 399 |
:author_id => 2, |
|
| 400 |
:container => Issue.find(1) |
|
| 401 |
) |
|
| 402 | ||
| 403 |
get(:download, :params => {:id => attachment.id})
|
|
| 404 |
assert_response :success |
|
| 405 |
assert_equal 'text/html', @response.media_type |
|
| 406 |
assert_match %r{\Aattachment}, @response.headers['Content-Disposition']
|
|
| 407 |
end |
|
| 408 | ||
| 394 | 409 |
def test_download_version_file_with_issue_tracking_disabled |
| 395 | 410 |
Project.find(1).disable_module! :issue_tracking |
| 396 | 411 |
get(:download, :params => {:id => 9})
|
- « Previous
- 1
- …
- 8
- 9
- 10
- Next »