Bugzilla – Attachment 70878 Details for
Bug 20081
Enable uploaded pdfs to be viewed inline
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20081: Set inline headers for uploaded pdfs
Bug-20081-Set-inline-headers-for-uploaded-pdfs.patch (text/plain), 2.71 KB, created by
Claire Gravely
on 2018-01-24 14:11:46 UTC
(
hide
)
Description:
Bug 20081: Set inline headers for uploaded pdfs
Filename:
MIME Type:
Creator:
Claire Gravely
Created:
2018-01-24 14:11:46 UTC
Size:
2.71 KB
patch
obsolete
>From b06fc558760daae804d8d93bff81aa9855d9da66 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 23 Jan 2018 20:21:57 +0000 >Subject: [PATCH] Bug 20081: Set inline headers for uploaded pdfs > >To test: >1 - Edit a framework and add the 'upload/pl' plugin to the 856 field >2 - Attach a pdf to one record >3 - Attach a different type of file to another >(To attach, edit a record in the framework edited above and find the > helper by the 856 field) >4 - Click the links on the record >5 - Verify the pdf opens inline >6 - Verify the other file does not >7 - prove t/db_dependent/Upload.t > >Signed-off-by: Claire Gravely <claire.gravely@bsz-bw.de> >--- > Koha/UploadedFile.pm | 15 +++++++++++---- > t/db_dependent/Upload.t | 13 ++++++++++++- > 2 files changed, 23 insertions(+), 5 deletions(-) > >diff --git a/Koha/UploadedFile.pm b/Koha/UploadedFile.pm >index 1e62ab6..9df1178 100644 >--- a/Koha/UploadedFile.pm >+++ b/Koha/UploadedFile.pm >@@ -134,10 +134,17 @@ Will be extended by report 14282 > > sub httpheaders { > my ( $self ) = @_; >- return ( >- '-type' => 'application/octet-stream', >- '-attachment' => $self->filename, >- ); >+ if( $self->filename =~ /\.pdf$/ ) { >+ return ( >+ '-type' => 'application/pdf', >+ 'Content-Disposition' => 'inline; filename='.$self->filename, >+ ); >+ } else { >+ return ( >+ '-type' => 'application/octet-stream', >+ '-attachment' => $self->filename, >+ ); >+ } > } > > =head2 CLASS METHODS >diff --git a/t/db_dependent/Upload.t b/t/db_dependent/Upload.t >index 41b3fff..3637244 100644 >--- a/t/db_dependent/Upload.t >+++ b/t/db_dependent/Upload.t >@@ -2,7 +2,7 @@ > > use Modern::Perl; > use File::Temp qw/ tempdir /; >-use Test::More tests => 12; >+use Test::More tests => 13; > use Test::Warn; > > use Test::MockModule; >@@ -316,6 +316,17 @@ subtest 'Testing delete_temporary' => sub { > 'Still 3 permanent uploads' ); > }; > >+subtest 'Testing download headers' => sub { >+ plan tests => 2; >+ my $test_pdf = Koha::UploadedFile->new({ filename => 'pdf.pdf', uploadcategorycode => 'B', filesize => 1000 }); >+ my $test_not = Koha::UploadedFile->new({ filename => 'pdf.not', uploadcategorycode => 'B', filesize => 1000 }); >+ my @pdf_expect = ( '-type'=>'application/pdf','Content-Disposition'=>'inline; filename=pdf.pdf' ); >+ my @not_expect = ( '-type'=>'application/octet-stream','-attachment'=>'pdf.not' ); >+ my @pdf_head = $test_pdf->httpheaders; >+ my @not_head = $test_not->httpheaders; >+ is_deeply(\@pdf_head, \@pdf_expect,"Get inline pdf headers for pdf"); >+ is_deeply(\@not_head, \@not_expect,"Get download headers for non pdf"); >+}; > # The end > $schema->storage->txn_rollback; > >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20081
:
70864
|
70878
|
73257