From 7fbea8a7fe9e7183b488277bc288c06ea024e819 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 27 Jul 2020 14:16:41 -0400 Subject: [PATCH] Bug 26072: Add ability to *not* force holds to be placed via the REST API even if AllowHoldPolicyOverride is enabled There are use cases where we need to be able to place holds via the API, but not place holds that are in violation of the current holds policy. If AllowHoldPolicyOverride is enabled, holds placed via the API will succeed regardless of violations of the current hold rules. Test Plan: 1) prove t/db_dependent/api/v1/holds.t --- Koha/REST/V1/Holds.pm | 4 +++- api/v1/swagger/paths/holds.json | 4 ++++ t/db_dependent/api/v1/holds.t | 10 +++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 87d7c05336..48e7829e9e 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -75,6 +75,8 @@ sub add { my $notes = $body->{notes}; my $hold_date = $body->{hold_date}; + my $disallow_override = $body->{_disallow_override}; + if(!C4::Context->preference( 'AllowHoldDateInFuture' ) && $hold_date) { return $c->render( status => 400, @@ -132,7 +134,7 @@ sub add { ? C4::Reserves::CanItemBeReserved( $patron_id, $item_id ) : C4::Reserves::CanBookBeReserved( $patron_id, $biblio_id ); - my $can_override = C4::Context->preference('AllowHoldPolicyOverride'); + my $can_override = $disallow_override ? 0 : C4::Context->preference('AllowHoldPolicyOverride'); unless ($can_override || $can_place_hold->{status} eq 'OK' ) { return $c->render( diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json index 847d3b83ca..235b08e989 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -201,6 +201,10 @@ "item_type": { "description": "Limit hold on one itemtype (ignored for item-level holds)", "type": [ "string", "null" ] + }, + "_disallow_override": { + "description": "Prevents AllowHoldPolicyOverride from forcing a hold to be placed even if it violates circulation rules", + "type": "boolean" } }, "required": [ "patron_id", "pickup_library_id" ] diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index f7436da0ee..fa2514f0ab 100644 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -348,7 +348,7 @@ subtest 'test AllowHoldDateInFuture' => sub { subtest 'test AllowHoldPolicyOverride' => sub { - plan tests => 5; + plan tests => 8; $dbh->do('DELETE FROM reserves'); @@ -370,6 +370,14 @@ subtest 'test AllowHoldPolicyOverride' => sub { t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 ); + $post_data->{_disallow_override} = Mojo::JSON::true; + + $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) + ->status_is(403) + ->json_has('/error'); + + delete $post_data->{_disallow_override}; + $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) ->status_is(201); }; -- 2.24.1 (Apple Git-126)