From 5491d1d4210a40a35879bcaa3dade2861a93ea4f Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 15 Apr 2020 12:48:02 -0400 Subject: [PATCH] Bug 14708: Prevent deletion of Anonymous Patron at Koha::Patron::delete Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit 63960cbb89ec22c0f984c8d02d140e76af03c18a) Signed-off-by: Andrew Fuerste-Henry --- Koha/Patron.pm | 3 +++ t/db_dependent/Koha/Patrons.t | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index d7fb1dd8f7..130ef5c860 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -361,6 +361,9 @@ other lists are kept. sub delete { my ($self) = @_; + my $anonymous_patron = C4::Context->preference("AnonymousPatron"); + return $self if $anonymous_patron && $self->id eq $anonymous_patron; + $self->_result->result_source->schema->txn_do( sub { # Cancel Patron's holds diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 4f434adc3c..e9ded6d1dd 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -1063,7 +1063,7 @@ subtest 'notice_email_address' => sub { }; subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { - plan tests => 4; + plan tests => 5; # TODO create a subroutine in t::lib::Mocks my $branch = $builder->build({ source => 'Branch' }); @@ -1077,6 +1077,15 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); + subtest 'Anonymous Patron should be undeleteable' => sub { + plan tests => 1; + + my $anonymous_patron = Koha::Patrons->find( $anonymous->{borrowernumber} ); + $anonymous_patron->delete(); + $anonymous_patron = Koha::Patrons->find( $anonymous->{borrowernumber} ); + is( $anonymous_patron->id, $anonymous->{borrowernumber}, "Anonymous Patron was not deleted" ); + }; + subtest 'patron privacy is 1 (default)' => sub { plan tests => 9; -- 2.39.5