From 6605ccd1c16e00df2cd6a7b606ca4a58a82100dd 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 ++++++++++++-- t/db_dependent/Reserves.t | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index a42168bc72..a41d968f42 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -340,6 +340,11 @@ sub CanBookBeReserved{ my $canReserve = { status => '' }; foreach my $itemnumber (@itemnumbers) { $canReserve = CanItemBeReserved( $borrowernumber, $itemnumber, $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; @@ -448,10 +453,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, @@ -588,7 +594,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 diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index c4afba6424..5c4b0b64df 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -1083,7 +1083,7 @@ subtest 'reserves.item_level_hold' => sub { subtest 'test opacitemholds rules in staff context' => sub { plan tests => 2; - C4::Context->interface('intranet'); + C4::Context->interface('intranet'); Koha::CirculationRules->set_rules( { branchcode => undef, -- 2.35.1