Bug 26181: Disable override by default in /holds
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 10 Aug 2020 20:30:25 +0000 (17:30 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 12 Feb 2021 11:14:50 +0000 (12:14 +0100)
This patch disables AllowHoldPolicyOverride by default in /holds. It
also adds a header that can be used to request the override explicitly.

Tests are added for this behaviour

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/holds.t
=> FAIL: Tests fail because the behaviour is not implemented
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/REST/V1/Holds.pm
api/v1/swagger/paths/holds.json

index ee346f6ffee394a40f5cf68062ccae4cf2a8e41d..9020c57a47de6bd6059779d1a706a4cecc9b905a 100644 (file)
@@ -19,6 +19,8 @@ use Modern::Perl;
 
 use Mojo::Base 'Mojolicious::Controller';
 
+use Mojo::JSON qw(decode_json);
+
 use C4::Biblio;
 use C4::Reserves;
 
@@ -169,7 +171,12 @@ sub add {
             $can_place_hold->{status} = 'tooManyReserves';
         }
 
-        my $can_override = C4::Context->preference('AllowHoldPolicyOverride');
+        my $override_header = $c->req->headers->header('x-koha-override');
+        $override_header = decode_json($override_header)
+          if $override_header;
+
+        my $can_override = $override_header->{AllowHoldPolicyOverride}
+          and C4::Context->preference('AllowHoldPolicyOverride');
 
         unless ($can_override || $can_place_hold->{status} eq 'OK' ) {
             return $c->render(
index a578adb252cecd7ba2b5091d1b01dd3842bb1910..c71fe1cacf976a2cf2a0d5ded5ada3727baee3f6 100644 (file)
         "permissions": {
           "reserveforothers": "1"
         }
+      },
+      "x-koha-override": {
+        "AllowHoldPolicyOverride": 1
       }
     }
   },