From 95ed8dfbe8f1a3cd229a54ea32ae75f71d83de16 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Wed, 13 Mar 2019 09:10:56 +0100 Subject: [PATCH] Bug 29480: Add new systempreference PatronSelfRegistrationUseridGenerationMethod and add email as option. Test plan - Install patch and run koha-upgrade-schema - The systempreference PatronSelfRegistrationUseridGenerationMethod should be found in the adminstrative interface under OPAC -> Self registration and modification - Also make sure - Make sure that PatronSelfRegistration is set to Allow and PatronSelfRegistrationDefaultCategory is set to an existing borrower category - Make sure that PatronSelfModificationBorrowerUnwantedField doesn't prevent the input of an email address in the self registration form. (I.e., make sure "email" is NOT selected for exclusion.) - Go to opac and self register a patron and verify that the userid is on the form firstname.surname. - Change systempreference to 'email' - Go to OPAC and self register a patron and make sure to add a valid email address. - Verify the that the userid is the email adress. - Go to OPAC and self register a patron using the SAME valid email adress as above (to provoke a conflicting userid). - Verify that the userid is on the form firstname.surname. --- Koha/Patron.pm | 41 ++++++++++++------- ...trationUseridGenerationMethod_syspref.perl | 11 +++++ .../en/modules/admin/preferences/opac.pref | 7 ++++ 3 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_29480-add_PatronSelfRegistrationUseridGenerationMethod_syspref.perl diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 68877c2e10..26bb3616a6 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1518,21 +1518,32 @@ Set a generated userid ($firstname.$surname if there is a $firstname, or $surnam sub generate_userid { my ($self) = @_; my $offset = 0; - my $firstname = $self->firstname // q{}; - my $surname = $self->surname // q{}; - #The script will "do" the following code and increment the $offset until the generated userid is unique - do { - $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; - $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; - my $userid = lc(($firstname)? "$firstname.$surname" : $surname); - $userid = NFKD( $userid ); - $userid =~ s/\p{NonspacingMark}//g; - $userid .= $offset unless $offset == 0; - $self->userid( $userid ); - $offset++; - } while (! $self->has_valid_userid ); - - return $self; + my $email = $self->first_valid_email_address; + + if (defined($email) && $email ne '' && length($email) <= 75 && + C4::Context->preference('PatronSelfRegistrationUseridGenerationMethod') eq 'email') { + # Uniqueness of email as userid is verified by + # has_valid_userid, with fallback to the default method. + $self->userid( $email ); + } + + if (!$self->has_valid_userid) { + my $firstname = $self->firstname // q{}; + my $surname = $self->surname // q{}; + #The script will "do" the following code and increment the $offset until the generated userid is unique + do { + $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; + $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; + my $userid = lc(($firstname)? "$firstname.$surname" : $surname); + $userid = NFKD( $userid ); + $userid =~ s/\p{NonspacingMark}//g; + $userid .= $offset unless $offset == 0; + $self->userid( $userid ); + $offset++; + } while (! $self->has_valid_userid ); + } + + return $self; } =head3 add_extended_attribute diff --git a/installer/data/mysql/atomicupdate/bug_29480-add_PatronSelfRegistrationUseridGenerationMethod_syspref.perl b/installer/data/mysql/atomicupdate/bug_29480-add_PatronSelfRegistrationUseridGenerationMethod_syspref.perl new file mode 100644 index 0000000000..5895bee1e2 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_29480-add_PatronSelfRegistrationUseridGenerationMethod_syspref.perl @@ -0,0 +1,11 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + + $dbh->do(<<'EOF'); +INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type`) VALUES +('PatronSelfRegistrationUseridGenerationMethod', 'default', 'default|email', 'Method for generating userid of of a borrower when self registering in OPAC. Fallback to generating a userid from the name of the borrower.', ''); +EOF + + # Always end with this (adjust the bug info) + NewVersion( $DBversion, 29480, "Add new system preference PatronSelfRegistrationUseridGenerationMethod"); +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 9f9ec8dd08..14b1a4e012 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -863,6 +863,13 @@ OPAC: yes: Require no: "Don't require" - patrons to confirm their email address by entering it twice. + - + - Use + - pref: PatronSelfRegistrationUseridGenerationMethod + choices: + default: "firstname.surname[uniqueness number, if needed]" + email: "email address" + - to generate the user name of a borrower when self registering in OPAC. - - pref: OPACPatronDetails choices: -- 2.20.1