From 2e028b687b09df955d9ae143afda2ac61f18898e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 14 Feb 2017 10:52:14 +0100 Subject: [PATCH] Bug 18087: Handle invalid filetypes Content-Type: text/plain; charset=utf-8 If an invalid file is used as biblionumber list, we should display a message. Test plan: 1/ Use csv, plain text files => Should work 2/ Use invalid files (binary files like pdf, doc*, xsl*, etc.) => Should not work and see a warning message. Amended patch after signoff: Remove one warn debug line Signed-off-by: Joy Nelson Signed-off-by: Marcel de Rooy --- koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt | 9 +++++++++ tools/export.pl | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt index 470c588..cfa252c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt @@ -47,6 +47,15 @@ $(document).ready(function() {
+[% FOR m IN messages %] +
+ [% SWITCH m.code %] + [% CASE 'invalid_mimetype' %]The file used does not have a valid format. Only csv and txt are allowed. + [% CASE %][% m.code %] + [% END %] +
+[% END %] +
  • Export bibliographic records
  • diff --git a/tools/export.pl b/tools/export.pl index b1ce09c..ecf4a04 100755 --- a/tools/export.pl +++ b/tools/export.pl @@ -69,6 +69,17 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( my @branch = $query->multi_param("branch"); +my @messages; +if ( $op eq 'export' ) { + my $filename = $query->param('id_list_file'); + my $mimetype = $query->uploadInfo($filename)->{'Content-Type'}; + my @valid_mimetypes = qw( application/octet-stream text/csv text/plain ); + unless ( grep { /^$mimetype$/ } @valid_mimetypes ) { + push @messages, { type => 'alert', code => 'invalid_mimetype' }; + $op = ''; + } +} + if ( $op eq "export" ) { my $export_remove_fields = $query->param("export_remove_fields") || q||; @@ -302,6 +313,7 @@ else { authority_types => $authority_types, export_remove_fields => C4::Context->preference("ExportRemoveFields"), csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ], + messages => \@messages, ); output_html_with_http_headers $query, $cookie, $template->output; -- 2.1.4