diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 0c6f950585..a1d0276977 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 e337c37604..5df6befe63 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' } )