Bug 14708: Don't allow merging of other patron records into Anonymous Patron

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>
(cherry picked from commit e2032ccfd3)

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
This commit is contained in:
Kyle M Hall 2020-04-29 07:22:26 -04:00 committed by Andrew Fuerste-Henry
parent 2efc873e28
commit aef74910e5
2 changed files with 10 additions and 4 deletions

View File

@ -557,6 +557,9 @@ sub siblings {
sub merge_with {
my ( $self, $patron_ids ) = @_;
my $anonymous_patron = C4::Context->preference("AnonymousPatron");
return if $anonymous_patron && $self->id eq $anonymous_patron;
my @patron_ids = @{ $patron_ids };
# Ensure the keeper isn't in the list of patrons to merge
@ -569,9 +572,7 @@ sub merge_with {
$self->_result->result_source->schema->txn_do( sub {
foreach my $patron_id (@patron_ids) {
if ( my $anonymous_patron = C4::Context->preference("AnonymousPatron") ) {
next if $patron_id eq $anonymous_patron;
}
next if $patron_id eq $anonymous_patron;
my $patron = Koha::Patrons->find( $patron_id );

View File

@ -1692,7 +1692,7 @@ subtest 'BorrowersLog tests' => sub {
$schema->storage->txn_rollback;
subtest 'Test Koha::Patrons::merge' => sub {
plan tests => 111;
plan tests => 113;
my $schema = Koha::Database->new()->schema();
@ -1738,6 +1738,11 @@ subtest 'Test Koha::Patrons::merge' => sub {
is( Koha::Patrons->find($loser_2), undef, 'Loser 2 has been deleted' );
is( ref Koha::Patrons->find($anonymous_patron), 'Koha::Patron', 'Anonymous Patron was not deleted' );
$anonymous_patron = Koha::Patrons->find($anonymous_patron);
$results = $anonymous_patron->merge_with( [ $keeper->id ] );
is( $results, undef, "Anonymous patron cannot have other patrons merged into it" );
is( Koha::Patrons->search( { borrowernumber => $keeper->id } )->count, 1, "Patron from attempted merge with AnonymousPatron still exists" );
t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
$schema->storage->txn_rollback;
};