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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 1fc82dd827)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Marcel de Rooy 2023-11-24 10:50:54 +00:00 committed by Fridolin Somers
parent 65460128f1
commit 24b14de398

View file

@ -74,11 +74,12 @@ sub under {
$is_plugin = 1; $is_plugin = 1;
} }
if ( $is_public if ($is_public) {
and !C4::Context->preference('RESTPublicAPI') ) Koha::Exceptions::UnderMaintenance->throw('Under maintenance')
{ if C4::Context->preference('OPACMaintenance');
Koha::Exceptions::Authorization->throw( 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/#) { if ( $c->req->url->to_abs->path =~ m#^/api/v1/oauth/# || $c->req->url->to_abs->path =~ m#^/api/v1/public/oauth/#) {