Bugzilla – Attachment 49854 Details for
Bug 14686
New menu option and permission for file uploading
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14686: [QA Follow-up] Move allows_add_by to Upload.pm
Bug-14686-QA-Follow-up-Move-allowsaddby-to-Uploadp.patch (text/plain), 5.25 KB, created by
Jonathan Druart
on 2016-04-04 13:22:49 UTC
(
hide
)
Description:
Bug 14686: [QA Follow-up] Move allows_add_by to Upload.pm
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-04-04 13:22:49 UTC
Size:
5.25 KB
patch
obsolete
>From de0a147772d5fa06a731df20994e0d3dc2cd0570 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Fri, 1 Apr 2016 11:14:15 +0200 >Subject: [PATCH] Bug 14686: [QA Follow-up] Move allows_add_by to Upload.pm > >As requested by QA, the sub should be moved. > >Test plan: >See previous patches. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > Koha/Schema/Result/UploadedFile.pm | 16 +--------------- > Koha/Upload.pm | 21 +++++++++++++++++++++ > t/db_dependent/Upload.t | 12 ++++++------ > tools/upload-file.pl | 3 +-- > 4 files changed, 29 insertions(+), 23 deletions(-) > >diff --git a/Koha/Schema/Result/UploadedFile.pm b/Koha/Schema/Result/UploadedFile.pm >index 8e2106b..1eaab71 100644 >--- a/Koha/Schema/Result/UploadedFile.pm >+++ b/Koha/Schema/Result/UploadedFile.pm >@@ -124,19 +124,5 @@ __PACKAGE__->set_primary_key("id"); > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Cq/HSuTaBxZH2qSGEddoaQ > > >-sub allows_add_by { >- my ( $self, $userid ) = @_; # do not confuse with borrowernumber >- my $flags = [ >- { tools => 'upload_general_files' }, >- { circulate => 'circulate_remaining_permissions' }, >- { tools => 'stage_marc_import' }, >- { tools => 'upload_local_cover_images' }, >- ]; >- require C4::Auth; >- foreach( @$flags ) { >- return 1 if C4::Auth::haspermission( $userid, $_ ); >- } >- return; >-} >- >+# You can replace this text with custom code or comments, and it will be preserved on regeneration > 1; >diff --git a/Koha/Upload.pm b/Koha/Upload.pm >index 5cd1c62..ceff56a 100644 >--- a/Koha/Upload.pm >+++ b/Koha/Upload.pm >@@ -240,6 +240,27 @@ sub httpheaders { > ); > } > >+=head2 allows_add_by >+ >+ allows_add_by checks if $userid has permission to add uploaded files >+ >+=cut >+ >+sub allows_add_by { >+ my ( $class, $userid ) = @_; # do not confuse with borrowernumber >+ my $flags = [ >+ { tools => 'upload_general_files' }, >+ { circulate => 'circulate_remaining_permissions' }, >+ { tools => 'stage_marc_import' }, >+ { tools => 'upload_local_cover_images' }, >+ ]; >+ require C4::Auth; >+ foreach( @$flags ) { >+ return 1 if C4::Auth::haspermission( $userid, $_ ); >+ } >+ return; >+} >+ > =head1 INTERNAL ROUTINES > > =cut >diff --git a/t/db_dependent/Upload.t b/t/db_dependent/Upload.t >index 31d8767..3e67f8e 100644 >--- a/t/db_dependent/Upload.t >+++ b/t/db_dependent/Upload.t >@@ -84,7 +84,7 @@ subtest 'Test07' => sub { > plan tests => 2; > test07(); > }; >-subtest 'Test08: UploadedFile->allows_add_by' => sub { >+subtest 'Test08: allows_add_by' => sub { > plan tests => 4; > test08(); > }; >@@ -176,26 +176,26 @@ sub test07 { #simple test for httpheaders and getCategories > is( @$cat >= 1, 1, 'getCategories returned at least one category' ); > } > >-sub test08 { # UploadedFile->allows_add_by >+sub test08 { # allows_add_by > my $builder = t::lib::TestBuilder->new; > my $patron = $builder->build({ > source => 'Borrower', > value => { flags => 0 }, #no permissions > }); > my $patronid = $patron->{borrowernumber}; >- is( Koha::Schema::Result::UploadedFile->allows_add_by( $patron->{userid} ), >+ is( Koha::Upload->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::Schema::Result::UploadedFile->allows_add_by( $patron->{userid} ), >+ is( Koha::Upload->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::Schema::Result::UploadedFile->allows_add_by( $patron->{userid} ), >+ is( Koha::Upload->allows_add_by( $patron->{userid} ), > 1, 'Patron should be allowed now to add uploaded files' ); > > # remove all tools and add upload_general_files only >@@ -209,7 +209,7 @@ sub test08 { # UploadedFile->allows_add_by > code => 'upload_general_files', > }, > }); >- is( Koha::Schema::Result::UploadedFile->allows_add_by( $patron->{userid} ), >+ is( Koha::Upload->allows_add_by( $patron->{userid} ), > 1, 'Patron is still allowed to add uploaded files' ); > } > >diff --git a/tools/upload-file.pl b/tools/upload-file.pl >index b410934..a64ce28 100755 >--- a/tools/upload-file.pl >+++ b/tools/upload-file.pl >@@ -28,7 +28,6 @@ use URI::Escape; > use C4::Context; > use C4::Auth qw/check_cookie_auth haspermission/; > use Koha::Upload; >-use Koha::Schema::Result::UploadedFile; > > # upload-file.pl must authenticate the user > # before processing the POST request, >@@ -42,7 +41,7 @@ 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::Schema::Result::UploadedFile->allows_add_by( $uid ); >+my $allowed = Koha::Upload->allows_add_by( $uid ); > > if( $auth_status ne 'ok' || !$allowed ) { > send_reply( 'denied' ); >-- >2.7.0
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 14686
:
49257
|
49258
|
49259
|
49260
|
49261
|
49552
|
49553
|
49554
|
49780
|
49835
|
49836
|
49851
|
49852
|
49853
| 49854 |
49855