From b747df5b88363336bf4259ddda1ab27299bf6227 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 9 Oct 2025 15:23:50 +0100 Subject: [PATCH] Bug 39336: Public Biblio endpoint should honour OpacSuppression syspref This patch makes the Public Biblio endpoint respect the OpacSuppression system preference and the biblio.opac_suppressed field introduced in Bug 38330. When OpacSuppression is enabled and a biblio has opac_suppressed set to 1, the endpoint now returns a 404 (Not Found) response instead of exposing the bibliographic record. Test plan: 1. Apply patch 2. Run: prove t/db_dependent/api/v1/biblios.t 3. Verify all tests pass, including the new OpacSuppression subtest 4. Test manually: - Enable OpacSuppression syspref - Set a biblio's opac_suppressed field to 1 - Access /api/v1/public/biblios/{biblio_id} - Confirm it returns 404 - Set opac_suppressed to 0 - Confirm it returns 200 with the record - Disable OpacSuppression syspref - Confirm record is visible regardless of opac_suppressed value --- Koha/REST/V1/Biblios.pm | 5 +++++ t/db_dependent/api/v1/biblios.t | 30 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 94bca50e83b..a4d50e38005 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -161,6 +161,11 @@ sub get_public { my $schema = $biblio->metadata->schema // C4::Context->preference("marcflavour"); my $patron = $c->stash('koha.user'); + # Check if the bibliographic record is suppressed in OPAC + if ( C4::Context->preference('OpacSuppression') && $biblio->opac_suppressed ) { + return $c->render_resource_not_found("Bibliographic record"); + } + # Check if the bibliographic record should be hidden for unprivileged access # unless there's a logged in user, and there's an exception for it's category my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems'); diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t index 9cf8db47a47..0e84d86e031 100755 --- a/t/db_dependent/api/v1/biblios.t +++ b/t/db_dependent/api/v1/biblios.t @@ -292,7 +292,7 @@ subtest 'delete() tests' => sub { subtest 'get_public() tests' => sub { - plan tests => 25; + plan tests => 26; $schema->storage->txn_begin; @@ -425,6 +425,34 @@ subtest 'get_public() tests' => sub { t::lib::Mocks::mock_preference('OpacHiddenItems'); }; + subtest 'OpacSuppression tests' => sub { + + plan tests => 8; + + # Test with OpacSuppression enabled and biblio suppressed + t::lib::Mocks::mock_preference( 'OpacSuppression', 1 ); + $biblio->set( { opac_suppressed => 1 } )->store; + + $t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) + ->status_is( 404, 'OpacSuppression enabled + opac_suppressed => hidden' ); + + # Test with OpacSuppression enabled but biblio not suppressed + $biblio->set( { opac_suppressed => 0 } )->store; + $t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) + ->status_is( 200, 'OpacSuppression enabled + not suppressed => displayed' ); + + # Test with OpacSuppression disabled but biblio suppressed + t::lib::Mocks::mock_preference( 'OpacSuppression', 0 ); + $biblio->set( { opac_suppressed => 1 } )->store; + $t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) + ->status_is( 200, 'OpacSuppression disabled + opac_suppressed => displayed' ); + + # Test with both disabled + $biblio->set( { opac_suppressed => 0 } )->store; + $t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) + ->status_is( 200, 'OpacSuppression disabled + not suppressed => displayed' ); + }; + $biblio->delete; $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } ) -- 2.51.0