From ede8290c5d8677d83b5fa70e9ff3afc061ea3924 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 Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart --- 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 579962005b..384f0cbbc1 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.39.5