From c601fac2b1b6bbbd9ee442a8bfad2eff1911b649 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 17 Apr 2017 18:05:24 +0200 Subject: [PATCH] Bug 18445: Replace two use C4::Auth statements Content-Type: text/plain; charset=utf-8 Both Serials.pm and Virtualshelf.pm only need haspermission in a specific sub. Since loading the module at compile-time triggers early execution of the BEGIN block, this results in database access in the tests that are assumed to be database independent. At the same time we are resolving test failures in Matcher.t and Prices.t because the schema mock is too late. Test plan: [1] Do not yet apply this patch. Backup your database. [2] Drop the database and create a new empty one. [3] Run the tests in t. Look at Matcher.t and Prices.t too. You will see quite some occurrences of: DBD::mysql::st execute failed: Table 'koha_master.systempreferences' doesn't exist [for Statement "SELECT `me`.`variable`, `me`.`value`, `me`.`options`, `me`.`explanation`, `me`.`type` FROM `systempreferences` `me` WHERE ( `me`.`variable` = ? )" with ParamValues: 0='casauthentication'] at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1832. [4] Apply this patch. [5] Run the tests in t again. Check the results of Matcher.t and Prices.t. [6] Restore your database. [7] Run t/db_dependent/Serials_2.t to trigger the change in Serials. [8] Run t/db_dependent/Virtualshelves.t to test Koha/Virtualshelf. Signed-off-by: Marcel de Rooy --- C4/Serials.pm | 2 +- Koha/Virtualshelf.pm | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index c1316f2..b07984c 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -20,7 +20,6 @@ package C4::Serials; use Modern::Perl; -use C4::Auth qw(haspermission); use C4::Context; use DateTime; use Date::Calc qw(:all); @@ -2690,6 +2689,7 @@ sub _can_do_on_subscription { my $flags = C4::Context->userenv->{flags}; $userid ||= C4::Context->userenv->{'id'}; + require C4::Auth; if ( C4::Context->preference('IndependentBranches') ) { return 1 if C4::Context->IsSuperLibrarian() diff --git a/Koha/Virtualshelf.pm b/Koha/Virtualshelf.pm index 4e45c31..582864f 100644 --- a/Koha/Virtualshelf.pm +++ b/Koha/Virtualshelf.pm @@ -19,8 +19,6 @@ use Modern::Perl; use Carp; -use C4::Auth; - use Koha::Patrons; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); @@ -243,6 +241,7 @@ sub can_be_deleted { my $patron = Koha::Patrons->find( $borrowernumber ); + require C4::Auth; return 1 if $self->category == $PUBLIC and C4::Auth::haspermission( $patron->userid, { lists => 'delete_public_lists' } ); return 0; -- 2.1.4