From f6ff108c4b2c5a1bd995e5bb13fd50021ef89b4e 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) Added error message when trying to hold on the record and opacitemhold is set to "Force" to item-level hold 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 54af13d7f0..58ca10d1c3 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -347,6 +347,11 @@ sub CanBookBeReserved{ my $patron = Koha::Patrons->find( $borrowernumber ); while ( my $item = $items->next ) { $canReserve = CanItemBeReserved( $patron, $item, $pickup_branchcode, $params ); + if ( C4::Context->interface eq 'opac' ) { + my $opacitemholds = $canReserve->{rights}->{opacitemholds} // 'Y'; + return { status => 'recordHoldNotAllowed' } if $opacitemholds eq 'F'; + return { status => 'OK' } if $canReserve->{status} eq 'recordHoldsOnly'; + } return { status => 'OK' } if $canReserve->{status} eq 'OK'; } return $canReserve; @@ -459,10 +464,11 @@ sub CanItemBeReserved { categorycode => $borrower->{'categorycode'}, itemtype => $item->effective_itemtype, branchcode => $reserves_control_branch, - 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'; if ( defined $holds_per_record && $holds_per_record ne '' ){ if ( $holds_per_record == 0 ) { @@ -591,7 +597,11 @@ sub CanItemBeReserved { } } - return { status => 'OK' }; + if ( $opacitemholds eq "N" && C4::Context->interface eq 'opac') { + return { status => "recordHoldsOnly", rights => $rights }; + } + + return { status => 'OK', rights => $rights }; } =head2 CanReserveBeCanceledFromOpac -- 2.30.2