Browse Source

Bug 14708: Prevent deletion of Anonymous Patron at Koha::Patron::delete

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Kyle Hall 1 year ago
committed by Jonathan Druart
parent
commit
63960cbb89
  1. 3
      Koha/Patron.pm
  2. 11
      t/db_dependent/Koha/Patrons.t

3
Koha/Patron.pm

@ -360,6 +360,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

11
t/db_dependent/Koha/Patrons.t

@ -1022,7 +1022,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' });
@ -1036,6 +1036,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;

Loading…
Cancel
Save