From 01b936762569f09fe6f4bf4872c05406a1e66010 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 28 Apr 2021 14:56:33 -0300 Subject: [PATCH] Bug 28254: Make PUT /holds/:hold_id/pickup_location honour x-koha-override This patch adds a new parameter (x-koha-override header) to the route, and makes the controller pass this information (override requested) when the AllowHoldPolicyOverride syspref is set, to Koha::Hold->set_pickup_location. This way, under certain conditions, we can be sure the update wont' fail. To test: 1. Apply this patchset 2. Run: $ kshell k$ prove t/db_dependent/api/v1/holds.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/REST/V1/Holds.pm | 10 +++++++++- api/v1/swagger/paths/holds.json | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 384f0cbbc1..bea108f5d0 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -533,7 +533,15 @@ sub update_pickup_location { return try { - $hold->set_pickup_location({ library_id => $pickup_library_id }); + my $overrides = $c->stash('koha.overrides'); + my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride'); + + $hold->set_pickup_location( + { + library_id => $pickup_library_id, + override => $can_override + } + ); return $c->render( status => 200, diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json index eb130a02db..366cf35838 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -628,6 +628,13 @@ "operationId": "getHoldPickupLocations", "tags": ["holds"], "parameters": [ + { + "name": "x-koha-override", + "description": "Comma-separated list of overrides (valid values: any)", + "in": "header", + "type": "string", + "required": false + }, { "$ref": "../parameters.json#/hold_id_pp" }, -- 2.39.5