From a90abc412ae350c1d5ac4caeb97a2523ea292f0b Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 24 Nov 2023 10:50:54 +0000 Subject: [PATCH] Bug 34999: Throw exception for public routes if OPACMaintenance is enabled Test plan: [1] Try public endpoint like /api/v1/public/biblios/X/items. * Replace X by an existing biblionumber. You should receive a 200. [2] Enable OPACMaintenance. Set to Show. [3] Try same endpoint. You should get a 503 with a json error. Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall --- Koha/REST/V1/Auth.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm index 11cd523188d..948bed689bd 100644 --- a/Koha/REST/V1/Auth.pm +++ b/Koha/REST/V1/Auth.pm @@ -74,11 +74,12 @@ sub under { $is_plugin = 1; } - if ( $is_public - and !C4::Context->preference('RESTPublicAPI') ) - { + if ($is_public) { + Koha::Exceptions::UnderMaintenance->throw('Under maintenance') + if C4::Context->preference('OPACMaintenance'); Koha::Exceptions::Authorization->throw( - "Configuration prevents the usage of this endpoint by unprivileged users"); + "Configuration prevents the usage of this endpoint by unprivileged users") + if !C4::Context->preference('RESTPublicAPI'); } if ( $c->req->url->to_abs->path =~ m#^/api/v1/oauth/# || $c->req->url->to_abs->path =~ m#^/api/v1/public/oauth/#) { -- 2.30.2