Bug 18087: Handle invalid filetypes

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 <joy@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2017-02-14 10:52:14 +01:00 committed by Kyle M Hall
parent 18af48bffe
commit d43131c4fc
2 changed files with 21 additions and 0 deletions

View File

@ -47,6 +47,15 @@ $(document).ready(function() {
<div id="yui-main">
<div class="yui-b">
[% FOR m IN messages %]
<div class="dialog [% m.type %]">
[% 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 %]
</div>
[% END %]
<div id="exporttype" class="toptabs">
<ul>
<li><a href="#bibs">Export bibliographic records</a></li>

View File

@ -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;