From 2fb7dab4a411f53847d4df1cc1f34aaff86ac8c2 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 24 Oct 2025 13:06:23 +0200 Subject: [PATCH] Bug 41094: Fix search_anonymize_candidates, locked_account We should not allow anonymizing patrons with failed login attempts when the pref FailedLoginAttempts has not been set. Test plan: Run the test again from the previous patch. This should pass now. Choose a patron with a positive value (say 55) in borrowers.login_attempts or modify one. (NOTE: This patron will be anonymized in the test plan.) Empty pref value for FailedLoginAttempts. Set PatronAnonymizeDelay to 1. Fill dateexpiry for this patron to yesterday. Run cleanupdatabase.pl -confirm -v and check if the patron was NOT anonymized. * Anonymized 0 patrons Now set FailedLoginAttempts to a value (say 55) so that the patron is considered as locked. (This unrealistic value is for testing only.) MAKE SURE that you will not be anonymizing more patrons than you like in the next step! (Set login_attempts to value < 55 for all other patrons.) Run cleanupdatabase.pl -confirm -v again and check if the patron was anonymized. * Anonymized 1 patrons Restore the changed pref values. Signed-off-by: Marcel de Rooy Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Lucas Gass (cherry picked from commit 291c2f103d59fc624842a5917d36326daab35410) Signed-off-by: Paul Derscheid --- Koha/Patron.pm | 5 +++-- Koha/Patrons.pm | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 0b3d903df3..557092d68c 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -2013,8 +2013,9 @@ sub account_locked { my $FailedLoginAttempts = C4::Context->preference('FailedLoginAttempts'); return 1 if $FailedLoginAttempts - and $self->login_attempts - and $self->login_attempts >= $FailedLoginAttempts; + && $FailedLoginAttempts > 0 + && $self->login_attempts + && $self->login_attempts >= $FailedLoginAttempts; return 1 if ( $self->login_attempts || 0 ) < 0; # administrative lockout return 0; } diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index a1e83328ff..cc128faa68 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -305,10 +305,13 @@ sub search_anonymize_candidates { my $str = $parser->format_datetime($dt); $cond->{dateexpiry} = { '<=' => $str }; $cond->{anonymized} = 0; # not yet done - if ( $params->{locked} ) { - my $fails = C4::Context->preference('FailedLoginAttempts') || 0; + my $fails = C4::Context->preference('FailedLoginAttempts'); + + if ( $params->{locked} && $fails && $fails > 0 ) { # $fails should actually not be negative btw $cond->{login_attempts} = [ -and => { '!=' => undef }, { -not_in => [ 0, 1 .. $fails - 1 ] } ]; # -not_in does not like undef + } elsif ( $params->{locked} ) { + $cond->{login_attempts} = -1; } return $class->search($cond); }