From a8b015221e176012a794cbdc5dbd6a99cbde750f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 19 Aug 2019 16:16:30 +0000 Subject: [PATCH] Bug 23473: Allow overwrite of passwords during import To test: 1 - Have some patrons in your system 2 - Export some of their info via reports SELECT cardnumber, userid, surname, firstname, password, branchcode, categorycode 3 - Edit the file from above, changing all the password lines 4 - Import the file with overwrite 5 - Confirm passwords have not changed (run the report again and confirm the hashes are the same) 6 - Apply patch 7 - Restart all the things 8 - Check the new box on import screen to overwrite passwrods 9 - Import file again 10 - Confirm passwords have changed 11 - Signin using new password to verify the hash is the password as supplied 12 - Repeat via commandline import supplying --overwrite_passwords option 13 - Verify works as expected 14 - Prove -v t/db_dependent/Koha/Patrons/Import.t --- Koha/Patron.pm | 1 - Koha/Patrons/Import.pm | 8 +++-- .../prog/en/modules/tools/import_borrowers.tt | 15 +++++++- misc/import_patrons.pl | 3 ++ t/db_dependent/Koha/Patrons/Import.t | 41 +++++++++++++++++++++- tools/import_borrowers.pl | 1 + 6 files changed, 64 insertions(+), 5 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index f0ab2d4d3e..64c7b3216b 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -225,7 +225,6 @@ sub store { # Make a copy of the plain text password for later use $self->plain_text_password( $self->password ); - # Create a disabled account if no password provided $self->password( $self->password ? Koha::AuthUtils::hash_password( $self->password ) diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm index b18db0d7ad..70a5244f72 100644 --- a/Koha/Patrons/Import.pm +++ b/Koha/Patrons/Import.pm @@ -72,6 +72,7 @@ sub import_patrons { my $defaults = $params->{defaults}; my $ext_preserve = $params->{preserve_extended_attributes}; my $overwrite_cardnumber = $params->{overwrite_cardnumber}; + my $overwrite_passwords = $params->{overwrite_passwords}; my $extended = C4::Context->preference('ExtendedPatronAttributes'); my $set_messaging_prefs = C4::Context->preference('EnhancedMessagingPreferences'); @@ -236,8 +237,8 @@ sub import_patrons { # use values from extant patron unless our csv file includes this column or we provided a default. # FIXME : You cannot update a field with a perl-evaluated false value using the defaults. - # The password is always encrypted, skip it! - next if $col eq 'password'; + # The password is always encrypted, skip it unless we are forcing overwrite! + next if $col eq 'password' && !$overwrite_passwords; unless ( exists( $csvkeycol{$col} ) || $defaults->{$col} ) { $borrower{$col} = $member->{$col} if ( $member->{$col} ); @@ -282,6 +283,9 @@ sub import_patrons { ); } } + if ($overwrite_passwords){ + $patron->set_password({ password => $borrower{password} }); + } if ($extended) { if ($ext_preserve) { my $old_attributes = GetBorrowerAttributes($borrowernumber); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt index 2133770199..3d28940de5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt @@ -217,6 +217,12 @@
  • +