From ba3a2fe79fd5505b8c925f383d28ed9cceaedac5 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Thu, 7 May 2020 12:33:46 +0200 Subject: [PATCH] Bug 25408: Add "opacitemholds" checks in CanBookBeReserved & CanItemBeReserved The rule "opacitemholds" seemed not to be controlled in some cases. This patch adds a control for this issuingrule in such a way it is checked across all interfaces (staff, opac, api) To test: 0 - Apply patches 1 - Set rule to "Don't allow" item specific holds on opac 2 - Attempt to place hold on staff side 3 - Hold is still allowed 4 - Attempt to place hold from opac or api 5 - Hold is not allowed 6 - Change rule to 'force' 7 - Item-level hold can be placed in all interfaces 8 - Record-level hold cannot be placed in all interfaces Signed-off-by: Victor Grousset/tuxayo --- C4/Reserves.pm | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index a658646407..327499dcd3 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -320,6 +320,8 @@ See CanItemBeReserved() for possible return values. sub CanBookBeReserved{ my ($borrowernumber, $biblionumber, $pickup_branchcode, $params) = @_; + my $patron = Koha::Patrons->find( $borrowernumber ); + my $borrower = $patron->unblessed; # Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set) if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions') @@ -335,9 +337,13 @@ sub CanBookBeReserved{ } my $canReserve = { status => '' }; + my ($rights,$item); + foreach my $itemnumber (@itemnumbers) { $canReserve = CanItemBeReserved( $borrowernumber, $itemnumber, $pickup_branchcode, $params ); + return { status => 'recordHoldNotAllowed' } if $canReserve->{rights}->{opacitemholds} eq 'F'; return { status => 'OK' } if $canReserve->{status} eq 'OK'; + return { status => 'OK' } if $canReserve->{status} eq 'recordHoldsOnly'; } return $canReserve; } @@ -442,10 +448,11 @@ sub CanItemBeReserved { categorycode => $borrower->{'categorycode'}, itemtype => $item->effective_itemtype, branchcode => $branchcode, - rules => ['holds_per_record','holds_per_day'] + rules => ['holds_per_record','holds_per_day','opacitemholds'] }); my $holds_per_record = $rights->{holds_per_record} // 1; my $holds_per_day = $rights->{holds_per_day}; + my $opacitemholds = $rights->{opacitemholds} // 'Y'; my $search_params = { borrowernumber => $borrowernumber, @@ -454,6 +461,16 @@ sub CanItemBeReserved { $search_params->{found} = undef if $params->{ignore_found_holds}; my $holds = Koha::Holds->search($search_params); + + $item = Koha::Items->find( $itemnumber ); + + $holds = Koha::Holds->search( + { + borrowernumber => $borrowernumber, + biblionumber => $item->biblionumber, + } + ); + if ( defined $holds_per_record && $holds_per_record ne '' && $holds->count() >= $holds_per_record ) { return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record }; @@ -574,7 +591,11 @@ sub CanItemBeReserved { } } - return { status => 'OK' }; + if ( $opacitemholds eq "N" ) { + return { status => "recordHoldsOnly", right => $rights }; + } + + return { status => 'OK', rights => $rights }; } =head2 CanReserveBeCanceledFromOpac -- 2.11.0