Bugzilla – Attachment 97058 Details for
Bug 24379
Patron login attempts happen to be NULL instead of 0
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24379: Make login_attempts not nullable
Bug-24379-Make-loginattempts-not-nullable.patch (text/plain), 4.96 KB, created by
Nick Clemens
on 2020-01-08 21:41:42 UTC
(
hide
)
Description:
Bug 24379: Make login_attempts not nullable
Filename:
MIME Type:
Creator:
Nick Clemens
Created:
2020-01-08 21:41:42 UTC
Size:
4.96 KB
patch
obsolete
>From df239a5c73a1cf598fa15a984d49a49e587bccc7 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 8 Jan 2020 20:59:38 +0000 >Subject: [PATCH] Bug 24379: Make login_attempts not nullable > >While the column defaults to 0 in Koha::Object->store we set to NULL if NULLABLE > >When trying to reset a patrons password we check that the account is not administratively locked: >login_attempts != -1 > >This query does not return rows where login_attempts IS NULL. It will return accounts where login_attempts = 0 > >Let's default to 0 like we intend > >To test: >1 - Create a new patron >2 - Note their login_attempts is NULL > SELECT login_attempts FROM borrowers ORDER BY borrowernumber DESC LIMIT 1 >3 - Enable OpacResetPassword >4 - Attempt to reset password before logging in, you cannot >5 - Apply patch, updatedatabase, restart_all, update schema >6 - Create another patron >7 - Their login attempts should be 0 >8 - Attempt to reset password, it works! >--- > .../make_login_attempts_not_nullable.perl | 9 +++++++++ > installer/data/mysql/kohastructure.sql | 4 ++-- > t/db_dependent/Koha/Patron.t | 20 +++++++++++++++++++- > 3 files changed, 30 insertions(+), 3 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/make_login_attempts_not_nullable.perl > >diff --git a/installer/data/mysql/atomicupdate/make_login_attempts_not_nullable.perl b/installer/data/mysql/atomicupdate/make_login_attempts_not_nullable.perl >new file mode 100644 >index 0000000000..0ba4e8a70b >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/make_login_attempts_not_nullable.perl >@@ -0,0 +1,9 @@ >+$DBversion = 'XXX'; >+if( CheckVersion( $DBversion ) ) { >+ $dbh->do( "UPDATE borrowers SET login_attempts=0 WHERE login_attempts IS NULL" ); >+ $dbh->do( "ALTER TABLE borrowers MODIFY COLUMN login_attempts int(4) NOT NULL DEFAULT 0" ); >+ $dbh->do( "UPDATE deletedborrowers SET login_attempts=0 WHERE login_attempts IS NULL" ); >+ $dbh->do( "ALTER TABLE deletedborrowers MODIFY COLUMN login_attempts int(4) NOT NULL DEFAULT 0" ); >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug XXXXX - Set login_attempts NOT NULL)\n"; >+} >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index ade8e7cc67..202a1ef221 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -587,7 +587,7 @@ CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrower > `updated_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- time of last change could be useful for synchronization with external systems (among others) > `lastseen` datetime default NULL, -- last time a patron has been seen (connected at the OPAC or staff interface) > `lang` varchar(25) NOT NULL default 'default', -- lang to use to send notices to this patron >- `login_attempts` int(4) default 0, -- number of failed login attemps >+ `login_attempts` int(4) NOT NULL default 0, -- number of failed login attemps > `overdrive_auth_token` MEDIUMTEXT default NULL, -- persist OverDrive auth token > `anonymized` TINYINT(1) NOT NULL DEFAULT 0, -- flag for data anonymization > KEY borrowernumber (borrowernumber), >@@ -1581,7 +1581,7 @@ CREATE TABLE `borrowers` ( -- this table includes information about your patrons > `updated_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- time of last change could be useful for synchronization with external systems (among others) > `lastseen` datetime default NULL, -- last time a patron has been seen (connected at the OPAC or staff interface) > `lang` varchar(25) NOT NULL default 'default', -- lang to use to send notices to this patron >- `login_attempts` int(4) default 0, -- number of failed login attemps >+ `login_attempts` int(4) NOT NULL default 0, -- number of failed login attemps > `overdrive_auth_token` MEDIUMTEXT default NULL, -- persist OverDrive auth token > `anonymized` TINYINT(1) NOT NULL DEFAULT 0, -- flag for data anonymization > UNIQUE KEY `cardnumber` (`cardnumber`), >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index adfcb60898..a8fee982a9 100644 >--- a/t/db_dependent/Koha/Patron.t >+++ b/t/db_dependent/Koha/Patron.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; > use Test::Exception; > > use Koha::Database; >@@ -154,3 +154,21 @@ subtest 'add_enrolment_fee_if_needed() tests' => sub { > $schema->storage->txn_rollback; > }; > }; >+ >+subtest 'login_attempts tests' => sub { >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ } >+ ); >+ my $patron_info = $patron->unblessed; >+ delete $patron_info->{login_attempts}; >+ my $new_patron = Koha::Patron->new($patron_info); >+ is( $new_patron->login_attempts, 0, "login_attempts defaults to 0 as expected"); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24379
:
97058
|
97073
|
105522
|
106846
|
106847
|
106890
|
107099