From cb5730b7156f6f24f5fc789a84901c777c3d8a8e Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 8 Mar 2021 13:05:34 -0300 Subject: [PATCH] Bug 27898: Make PUT /holds/:hold_id accept overrides This patch makes the route handle overriding pickup locations by passing the 'x-koha-override' header (set to 'any'). To test: 1. Apply the unit tests patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/holds.t => FAIL: Tests fail, because things cannot be overridden ATM. 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: Andrew Fuerste-Henry --- Koha/REST/V1/Holds.pm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 26fb90aaef..ffe42d123f 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -252,17 +252,22 @@ sub edit { my $hold = Koha::Holds->find( $hold_id ); unless ($hold) { - return $c->render( status => 404, - openapi => {error => "Hold not found"} ); + return $c->render( + status => 404, + openapi => { error => "Hold not found" } + ); } - my $body = $c->req->json; + my $overrides = $c->stash('koha.overrides'); + my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride'); + + my $body = $c->validation->output->{body}; my $pickup_library_id = $body->{pickup_library_id}; if ( defined $pickup_library_id - and not $hold->is_pickup_location_valid({ library_id => $pickup_library_id }) + && ( !$hold->is_pickup_location_valid({ library_id => $pickup_library_id }) && !$can_override ) ) { return $c->render( -- 2.11.0