From 4dc5f4b09fa8f570dbbc963c51b20e80fe8319c2 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. Signed-off-by: Magnus Enger Works as advertised. I will provide followups for the issues that have been pointed out. --- Koha/Patron.pm | 41 ++++++++++++------- ...trationUseridGenerationMethod_syspref.perl | 11 +++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../en/modules/admin/preferences/opac.pref | 7 ++++ 4 files changed, 45 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 96a72a393a..272fab6313 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1680,21 +1680,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/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index ae3d9e718f..d0a35cacd4 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -554,6 +554,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('PatronSelfRegistrationExpireTemporaryAccountsDelay','0',NULL,'If PatronSelfRegistrationDefaultCategory is enabled, this system preference controls how long a patron can have a temporary status before the account is deleted automatically. It is an integer value representing a number of days to wait before deleting a temporary patron account. Setting it to 0 disables the deleting of temporary accounts.','Integer'), ('PatronSelfRegistrationLibraryList','',NULL,'Only display libraries listed. If empty, all libraries are displayed.','Free'), ('PatronSelfRegistrationPrefillForm','1',NULL,'Display password and prefill login form after a patron has self registered','YesNo'), +('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.', ''), ('PatronSelfRegistrationVerifyByEmail','0',NULL,'If enabled, any patron attempting to register themselves via the OPAC will be required to verify themselves via email to activate their account.','YesNo'), ('PatronsPerPage','20','20','Number of Patrons Per Page displayed by default','Integer'), ('PatronQuickAddFields', '', NULL , 'A list of fields separated by "|" to be displayed along with mandatory fields in the patron quick add form if chosen at patron entry', 'Free' ), 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 d9641af5fe..69c201d566 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 @@ -802,6 +802,13 @@ OPAC: 1: Require 0: "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.32.0