From 43f9b6d87aa710eaf78047544728e00e3517b540 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 5 Sep 2016 13:50:54 +0200 Subject: [PATCH] Bug 17247: Check if patron is debarred in CanItemBeReserved This way, calls to ILS-DI HoldTitle and HoldItem do this check too --- C4/Reserves.pm | 6 ++++++ t/db_dependent/Holds.t | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index c9e270c..16bff6a 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -44,6 +44,7 @@ use Koha::Holds; use Koha::Libraries; use Koha::Items; use Koha::ItemTypes; +use Koha::Patrons; use List::MoreUtils qw( firstidx any ); use Carp; @@ -456,6 +457,7 @@ sub CanBookBeReserved{ cannotReserveFromOtherBranches, if syspref 'canreservefromotherbranches' is OK. tooManyReserves, if the borrower has exceeded his maximum reserve amount. notReservable, if holds on this item are not allowed + debarred, if patron is debarred =cut @@ -472,6 +474,10 @@ sub CanItemBeReserved{ my $biblioData = C4::Biblio::GetBiblioData( $item->{biblionumber} ); my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); + if (Koha::Patrons->find($borrowernumber)->is_debarred) { + return 'debarred'; + } + # If an item is damaged and we don't allow holds on damaged items, we can stop right here return 'damaged' if ( $item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems') ); diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index f9ddc46..aad314e 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -8,7 +8,7 @@ use t::lib::TestBuilder; use C4::Context; use C4::Branch; -use Test::More tests => 60; +use Test::More tests => 61; use MARC::Record; use C4::Biblio; use C4::Items; @@ -473,6 +473,16 @@ my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, ); is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), 'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); +my $debarred_borrowernumber = AddMember( + firstname => 'Debarred', + surname => 'Patron', + categorycode => $category->{categorycode}, + branchcode => $branch_1, + debarred => '9999-12-31', +); +is(CanItemBeReserved($debarred_borrowernumber, $itemnumber), + 'debarred', 'Debarred patron cannot reserve'); + # Helper method to set up a Biblio. sub create_helper_biblio { -- 2.1.4