From d222c3eee7a6a4e52ccb56fa1bf43e4c007f6265 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 22 Nov 2016 11:23:23 +0000 Subject: [PATCH] Bug 8361: Do not allow checkouts if no rules are defined We should require a circulation rule to allow checkouts and reject them if no rules are defined. Test plan: - Delete all issuing rules - Check an item out => Without this patch the checkout is allowed => With this patch applied it is rejected Signed-off-by: Mark Tompsett Signed-off-by: Nick Clemens Signed-off-by: Kyle M Hall (cherry picked from commit 11dfb2e0b2d32c313f556b623ee8522b4342af26) Signed-off-by: Katrin Fischer --- C4/Circulation.pm | 4 ++++ t/db_dependent/Circulation/TooMany.t | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 674a7fb6b0..5783038055 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -545,6 +545,10 @@ sub TooMany { } } + if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) { + return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; + } + # OK, the patron can issue !!! return; } diff --git a/t/db_dependent/Circulation/TooMany.t b/t/db_dependent/Circulation/TooMany.t index 3b60ef50b2..b055f7cdbc 100644 --- a/t/db_dependent/Circulation/TooMany.t +++ b/t/db_dependent/Circulation/TooMany.t @@ -92,15 +92,15 @@ C4::Context->set_userenv($patron->{borrowernumber}, $patron->{userid}, 'usercnum subtest 'no rules exist' => sub { plan tests => 2; - is( + is_deeply( C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ), - undef, - 'CO should be allowed, in any cases' + { reason => 'NO_RULE_DEFINED', max_allowed => 0 }, + 'CO should not be allowed, in any cases' ); - is( + is_deeply( C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ), - undef, - 'OSCO should be allowed, in any cases' + { reason => 'NO_RULE_DEFINED', max_allowed => 0 }, + 'OSCO should not be allowed, in any cases' ); }; -- 2.39.5