From dcb2895276fc91f8a54a1afe0af4186fbb1ceefb Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 29 Jul 2019 13:19:19 +0000 Subject: [PATCH] Bug 23392: Don;t display private notes in MARC 21 To test: 1 - Add some notes to a record in fields 541,542,561,583,590 2 - Ensure all of these are visible in the frameworks 3 - Note they appear in the 'Title notes'/'Description' tabs on OPAC/Staff client 4 - Mark first indicator '0' on all notes 5 - They still display 6 - Apply patch 7 - Notes no longer show on OPAC 8 - Notes still show on Staff client 9 - prove -v t/Biblio/GetMarcNotes.t --- C4/Biblio.pm | 13 ++++++++++++- Koha/Cache.pm | 1 + opac/opac-basket.pl | 2 +- opac/opac-detail.pl | 2 +- t/Biblio/GetMarcNotes.t | 15 +++++++++++++-- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 55a2c01890..443e445245 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1495,7 +1495,7 @@ sub GetMarcISSN { =cut sub GetMarcNotes { - my ( $record, $marcflavour ) = @_; + my ( $record, $marcflavour, $opac ) = @_; if (!$record) { carp 'GetMarcNotes called on undefined record'; return; @@ -1503,11 +1503,22 @@ sub GetMarcNotes { my $scope = $marcflavour eq "UNIMARC"? '3..': '5..'; my @marcnotes; + + #MARC21 specs indicate some notes should be private if first indicator 0 + my %maybe_private = ( + 541 => 1, + 542 => 1, + 561 => 1, + 583 => 1, + 590 => 1 + ); + my %blacklist = map { $_ => 1 } split( /,/, C4::Context->preference('NotesBlacklist')); foreach my $field ( $record->field($scope) ) { my $tag = $field->tag(); next if $blacklist{ $tag }; + next if $opac && $maybe_private{$tag} && !$field->indicator(1); if( $marcflavour ne 'UNIMARC' && $field->subfield('u') ) { # Field 5XX$u always contains URI # Examples: 505u, 506u, 510u, 514u, 520u, 530u, 538u, 540u, 542u, 552u, 555u, 561u, 563u, 583u diff --git a/Koha/Cache.pm b/Koha/Cache.pm index cf77257825..2bd577cd23 100644 --- a/Koha/Cache.pm +++ b/Koha/Cache.pm @@ -249,6 +249,7 @@ sub set_in_cache { ? $set_sub->( $key, $value ) : $self->{$cache}->set( $key, $value ); } + warn $expiry; } =head2 get_from_cache diff --git a/opac/opac-basket.pl b/opac/opac-basket.pl index 11d9387d78..db0a7ac98d 100755 --- a/opac/opac-basket.pl +++ b/opac/opac-basket.pl @@ -82,7 +82,7 @@ foreach my $biblionumber ( @bibs ) { }); $record_processor->process($record); next unless $record; - my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); + my $marcnotesarray = GetMarcNotes( $record, $marcflavour, 1 ); my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my $marcseriesarray = GetMarcSeries ($record,$marcflavour); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index e55ecb6a39..0facd004b9 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -766,7 +766,7 @@ if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) { ); } -my $marcnotesarray = GetMarcNotes ($record,$marcflavour); +my $marcnotesarray = GetMarcNotes ($record,$marcflavour,1); if( C4::Context->preference('ArticleRequests') ) { my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef; diff --git a/t/Biblio/GetMarcNotes.t b/t/Biblio/GetMarcNotes.t index 6068dcd92a..bb55226bdc 100755 --- a/t/Biblio/GetMarcNotes.t +++ b/t/Biblio/GetMarcNotes.t @@ -26,7 +26,7 @@ use MARC::Record; use C4::Biblio; subtest 'GetMarcNotes MARC21' => sub { - plan tests => 4; + plan tests => 11; t::lib::Mocks::mock_preference( 'NotesBlacklist', '520' ); my $record = MARC::Record->new; @@ -34,12 +34,23 @@ subtest 'GetMarcNotes MARC21' => sub { MARC::Field->new( '500', '', '', a => 'Note1' ), MARC::Field->new( '505', '', '', a => 'Note2', u => 'http://someserver.com' ), MARC::Field->new( '520', '', '', a => 'Note3 skipped' ), + MARC::Field->new( '541', '0', '', a => 'Note4 skipped on opac' ), + MARC::Field->new( '541', '', '', a => 'Note5' ), ); my $notes = C4::Biblio::GetMarcNotes( $record, 'MARC21' ); is( $notes->[0]->{marcnote}, 'Note1', 'First note' ); is( $notes->[1]->{marcnote}, 'Note2', 'Second note' ); is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' ); - is( @$notes, 3, 'No more notes' ); + is( $notes->[3]->{marcnote}, 'Note4 skipped on opac',"Not shows if not opac" ); + is( $notes->[4]->{marcnote}, 'Note5', 'Fifth note' ); + is( @$notes, 5, 'No more notes' ); + $notes = C4::Biblio::GetMarcNotes( $record, 'MARC21', 1 ); + is( $notes->[0]->{marcnote}, 'Note1', 'First note' ); + is( $notes->[1]->{marcnote}, 'Note2', 'Second note' ); + is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' ); + is( $notes->[3]->{marcnote}, 'Note5', 'Fifth note shows after fourth skipped' ); + is( @$notes, 4, 'No more notes' ); + }; subtest 'GetMarcNotes UNIMARC' => sub { -- 2.11.0