From 09cc946e1c3e3332d1834389bfd889c699ece9e3 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 4 Mar 2021 14:44:40 -0300 Subject: [PATCH] Bug 27863: Add a way to override pickup locations constraints If AllowHoldPolicyOverride is set, staff members are able to choose any branch marked as pickup location for a hold. The route for retrieving the valid pickup locations should provide a way to request the override. This patch does that, based on work from bug 27760. A new parameter is added: an x-koha-override header, with the value of 'any' that will force the override if the syspref is enabled. To test: 1. Apply this patches 2. Run: $ kshell k$ prove t/db_dependent/api/v1/holds.t => SUCCESS: Tests pass! 3. Sign off :-D --- Koha/REST/V1/Holds.pm | 13 ++++++++++--- api/v1/swagger/paths/holds.json | 7 +++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 9020c57a47d..2fb39cbad4c 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -464,11 +464,18 @@ sub pickup_locations { return try { my $ps_set; - if ( $hold->itemnumber ) { - $ps_set = $hold->item->pickup_locations( { patron => $hold->patron } ); + my $overrides = $c->stash('koha.overrides'); + + if ( $overrides->{any} and C4::Context->preference('AllowHoldPolicyOverride') ) { + $ps_set = Koha::Libraries->search({ pickup_location => 1 }); } else { - $ps_set = $hold->biblio->pickup_locations( { patron => $hold->patron } ); + if ( $hold->itemnumber ) { + $ps_set = $hold->item->pickup_locations( { patron => $hold->patron } ); + } + else { + $ps_set = $hold->biblio->pickup_locations( { patron => $hold->patron } ); + } } my $pickup_locations = $c->objects->search( $ps_set ); diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json index c71fe1cacf9..38603ce9a83 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -646,6 +646,13 @@ }, { "$ref": "../parameters.json#/q_header" + }, + { + "name": "x-koha-override", + "description": "Comma-separated list of overrides (valid values: any)", + "in": "header", + "type": "string", + "required": false } ], "produces": ["application/json"], -- 2.30.1