Bug 17501: Rename Upload to Uploader
Why? Koha::Uploader now only contains the actual CGI upload. The new name
better reflects its handler status.
Pragmatically, the difference between Uploaded and Uploader makes it
easier to specifically search for them in the codebase.
Test plan:
[1] Run t/db_dependent/Upload.t.
[2] Add an upload via the interface.
[3] Check the code:
git grep "Koha::Upload;"
git grep "Koha::Upload\->"
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
ba5cd24553
commit
3acee79310
|
|
@ -1,4 +1,4 @@
|
|||
package Koha::Upload;
|
||||
package Koha::Uploader;
|
||||
|
||||
# Copyright 2007 LibLime, Galen Charlton
|
||||
# Copyright 2011-2012 BibLibre
|
||||
|
|
@ -21,17 +21,17 @@ package Koha::Upload;
|
|||
|
||||
=head1 NAME
|
||||
|
||||
Koha::Upload - Facilitate file uploads (temporary and permanent)
|
||||
Koha::Uploader - Facilitate file uploads (temporary and permanent)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Koha::Upload;
|
||||
use Koha::Uploader;
|
||||
use Koha::UploadedFile;
|
||||
use Koha::UploadedFiles;
|
||||
|
||||
# add an upload (see tools/upload-file.pl)
|
||||
# the public flag allows retrieval via OPAC
|
||||
my $upload = Koha::Upload->new( public => 1, category => 'A' );
|
||||
my $upload = Koha::Uploader->new( public => 1, category => 'A' );
|
||||
my $cgi = $upload->cgi;
|
||||
# Do something with $upload->count, $upload->result or $upload->err
|
||||
|
||||
|
|
@ -10,9 +10,9 @@ use t::lib::TestBuilder;
|
|||
|
||||
use C4::Context;
|
||||
use Koha::Database;
|
||||
use Koha::Upload;
|
||||
use Koha::UploadedFile;
|
||||
use Koha::UploadedFiles;
|
||||
use Koha::Uploader;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
$schema->storage->txn_begin;
|
||||
|
|
@ -95,7 +95,7 @@ sub test01 {
|
|||
is( Koha::UploadedFile->temporary_directory, $tempdir,
|
||||
'Check temporary directory' );
|
||||
|
||||
my $upl = Koha::Upload->new({
|
||||
my $upl = Koha::Uploader->new({
|
||||
category => $uploads->[$current_upload]->[0]->{cat},
|
||||
});
|
||||
my $cgi= $upl->cgi;
|
||||
|
|
@ -118,7 +118,7 @@ sub test01 {
|
|||
}
|
||||
|
||||
sub test02 {
|
||||
my $upl = Koha::Upload->new({
|
||||
my $upl = Koha::Uploader->new({
|
||||
category => $uploads->[$current_upload]->[0]->{cat},
|
||||
public => 1,
|
||||
});
|
||||
|
|
@ -138,7 +138,7 @@ sub test02 {
|
|||
}
|
||||
|
||||
sub test03 {
|
||||
my $upl = Koha::Upload->new({ tmp => 1 }); #temporary
|
||||
my $upl = Koha::Uploader->new({ tmp => 1 }); #temporary
|
||||
my $cgi= $upl->cgi;
|
||||
is( $upl->count, 1, 'Upload 3 includes one temporary file' );
|
||||
my $rec = Koha::UploadedFiles->find( $upl->result );
|
||||
|
|
@ -146,7 +146,7 @@ sub test03 {
|
|||
}
|
||||
|
||||
sub test04 { # Fail on a file already there
|
||||
my $upl = Koha::Upload->new({
|
||||
my $upl = Koha::Uploader->new({
|
||||
category => $uploads->[$current_upload]->[0]->{cat},
|
||||
});
|
||||
my $cgi= $upl->cgi;
|
||||
|
|
@ -157,7 +157,7 @@ sub test04 { # Fail on a file already there
|
|||
}
|
||||
|
||||
sub test05 { # add temporary file with same name and contents, delete it
|
||||
my $upl = Koha::Upload->new({ tmp => 1 });
|
||||
my $upl = Koha::Uploader->new({ tmp => 1 });
|
||||
my $cgi= $upl->cgi;
|
||||
is( $upl->count, 1, 'Upload 5 adds duplicate temporary file' );
|
||||
my $id = $upl->result;
|
||||
|
|
@ -171,7 +171,7 @@ sub test05 { # add temporary file with same name and contents, delete it
|
|||
|
||||
# testing delete via UploadedFile (singular)
|
||||
# Note that find returns a Koha::Object
|
||||
$upl = Koha::Upload->new({ tmp => 1 });
|
||||
$upl = Koha::Uploader->new({ tmp => 1 });
|
||||
$upl->cgi;
|
||||
my $kohaobj = Koha::UploadedFiles->find( $upl->result );
|
||||
my $name = $kohaobj->filename;
|
||||
|
|
@ -208,19 +208,19 @@ sub test08 { # allows_add_by
|
|||
value => { flags => 0 }, #no permissions
|
||||
});
|
||||
my $patronid = $patron->{borrowernumber};
|
||||
is( Koha::Upload->allows_add_by( $patron->{userid} ),
|
||||
is( Koha::Uploader->allows_add_by( $patron->{userid} ),
|
||||
undef, 'Patron is not allowed to do anything' );
|
||||
|
||||
# add some permissions: edit_catalogue
|
||||
my $fl = 2**9; # edit_catalogue
|
||||
$schema->resultset('Borrower')->find( $patronid )->update({ flags => $fl });
|
||||
is( Koha::Upload->allows_add_by( $patron->{userid} ),
|
||||
is( Koha::Uploader->allows_add_by( $patron->{userid} ),
|
||||
undef, 'Patron is still not allowed to add uploaded files' );
|
||||
|
||||
# replace flags by all tools
|
||||
$fl = 2**13; # tools
|
||||
$schema->resultset('Borrower')->find( $patronid )->update({ flags => $fl });
|
||||
is( Koha::Upload->allows_add_by( $patron->{userid} ),
|
||||
is( Koha::Uploader->allows_add_by( $patron->{userid} ),
|
||||
1, 'Patron should be allowed now to add uploaded files' );
|
||||
|
||||
# remove all tools and add upload_general_files only
|
||||
|
|
@ -234,7 +234,7 @@ sub test08 { # allows_add_by
|
|||
code => 'upload_general_files',
|
||||
},
|
||||
});
|
||||
is( Koha::Upload->allows_add_by( $patron->{userid} ),
|
||||
is( Koha::Uploader->allows_add_by( $patron->{userid} ),
|
||||
1, 'Patron is still allowed to add uploaded files' );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use URI::Escape;
|
|||
|
||||
use C4::Context;
|
||||
use C4::Auth qw/check_cookie_auth haspermission/;
|
||||
use Koha::Upload;
|
||||
use Koha::Uploader;
|
||||
|
||||
# upload-file.pl must authenticate the user
|
||||
# before processing the POST request,
|
||||
|
|
@ -41,14 +41,14 @@ my %cookies = CGI::Cookie->fetch;
|
|||
my $sid = $cookies{'CGISESSID'}->value;
|
||||
my ( $auth_status, $sessionID ) = check_cookie_auth( $sid );
|
||||
my $uid = C4::Auth::get_session($sid)->param('id');
|
||||
my $allowed = Koha::Upload->allows_add_by( $uid );
|
||||
my $allowed = Koha::Uploader->allows_add_by( $uid );
|
||||
|
||||
if( $auth_status ne 'ok' || !$allowed ) {
|
||||
send_reply( 'denied' );
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my $upload = Koha::Upload->new( upload_pars($ENV{QUERY_STRING}) );
|
||||
my $upload = Koha::Uploader->new( upload_pars($ENV{QUERY_STRING}) );
|
||||
if( !$upload || !$upload->cgi || !$upload->count ) {
|
||||
# not one upload succeeded
|
||||
send_reply( 'failed', undef, $upload? $upload->err: undef );
|
||||
|
|
@ -70,7 +70,7 @@ sub send_reply { # response will be sent back as JSON
|
|||
}
|
||||
|
||||
sub upload_pars { # this sub parses QUERY_STRING in order to build the
|
||||
# parameter hash for Koha::Upload
|
||||
# parameter hash for Koha::Uploader
|
||||
my ( $qstr ) = @_;
|
||||
$qstr = Encode::decode_utf8( uri_unescape( $qstr ) );
|
||||
# category could include a utf8 character
|
||||
|
|
|
|||
Loading…
Reference in New Issue