From 0aeb017cb53c05c51e36da3666eb1bb9b51ce2d8 Mon Sep 17 00:00:00 2001 From: Alexander Blanchard Date: Tue, 8 Apr 2025 12:55:03 +0000 Subject: [PATCH] Bug 39579: Restrict Patron Self Reg Date of Birth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some libraries are getting dates of birth from the self-registration form that make patrons impossible ages, e.g. year of birth 1900. To Test: 1) Navigate to the oPac 2) Ensure you are not logged in 3) Below the log in, see 'Create an Account' 4) Click the link and complete the relevant fields 5) Add an unrealistic d.o.b e.g 1900 6) Complete the verification and click 'Submit' 7) Your acount has been created 8) Apply the patch 9) Navigate to the staff site 10) Navigate to Administration > SystemPreferences 11) Navigate to OPAC preferences 12) Identify PatronSelfRegistrationAgeRestriction 13) Add a maximum age in numberals e.g. 100 14) Repeat steps 1 - 6 15) An error message that you have exceeded max age will appear. 16) Alter your date of birth to make your age below that of the max age you set 17) Complete the verification 18) Your account should be created as normal Sponsored-by: Cheshire Signed-off-by: Emmanuel Bétemps --- ...9579-patronselfregistrationagerestriction.pl | 17 +++++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/opac.pref | 5 +++++ .../bootstrap/en/modules/opac-memberentry.tt | 3 +++ opac/opac-memberentry.pl | 4 ++++ 5 files changed, 30 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_39579-patronselfregistrationagerestriction.pl diff --git a/installer/data/mysql/atomicupdate/bug_39579-patronselfregistrationagerestriction.pl b/installer/data/mysql/atomicupdate/bug_39579-patronselfregistrationagerestriction.pl new file mode 100644 index 0000000000..cb2fd1d21c --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_39579-patronselfregistrationagerestriction.pl @@ -0,0 +1,17 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => '39579', + description => "Add system preference 'patronSelfRegistrationAgeRestriction'", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( " + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('PatronSelfRegistrationAgeRestriction', '', NULL, 'Patron\'s maximum age during self registration. If empty, no age restriction is applied.', 'Integer') + " ); + say_success( $out, "Added new system preference 'PatronSelfRegistrationAgeRestriction'" ); + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 2bf9d0b648..259d357a77 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -615,6 +615,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('PatronSelfModificationBorrowerUnwantedField','',NULL,'Name the fields you don\'t want to display when a patron is editing their information via the OPAC.','free'), ('PatronSelfModificationMandatoryField','',NULL,'Define the required fields when a patron is editing their information via the OPAC','free'), ('PatronSelfRegistration','0',NULL,'If enabled, patrons will be able to register themselves via the OPAC.','YesNo'), +('PatronSelfRegistrationAgeRestriction', '', NULL, 'Patron\'s maximum age during self registration. If empty, no age restriction is applied.', 'Integer'), ('PatronSelfRegistrationAlert','0',NULL,'If enabled, an alter will be shown on staff interface home page when there are self-registered patrons.','YesNo'), ('PatronSelfRegistrationBorrowerMandatoryField','surname|firstname',NULL,'Choose the mandatory fields for a patron\'s account, when registering via the OPAC.','free'), ('PatronSelfRegistrationBorrowerUnwantedField','',NULL,'Name the fields you don\'t want to display when registering a new patron via the OPAC.','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 ec83b17a01..1e956b6255 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 @@ -894,6 +894,11 @@ OPAC: 0: "Don't show" 1: "Show" - an alert on staff interface home page when there are patrons in the category defined by PatronSelfRegistrationDefaultCategory. + - + - "Patron's maximum age when registering: " + - pref: PatronSelfRegistrationAgeRestriction + class: integer + - "
Note: If empty, do not restrict patron's age during self registration" Suggestions: - - pref: OpacSuggestionManagedBy diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt index 3527cbaf80..94444c0455 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -115,6 +115,9 @@ [% IF field == "ERROR_age_limitations" %]
  • Patron's age is incorrect for their category.
  • [% END %] + [% IF field == "ERROR_age_limitations_self_registration" %] +
  • Patron's age exceeds the maximum age allowed.
  • + [% END %] [% END %] Please correct and resubmit. diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index b89ddbc547..e9caa46961 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -541,9 +541,13 @@ sub CheckForInvalidFields { my $age = $patron->get_age; my $borrowercategory = Koha::Patron::Categories->find( $borrower->{'categorycode'} ); my ( $low, $high ) = ( $borrowercategory->dateofbirthrequired, $borrowercategory->upperagelimit ); + my $upper_registration_age_restriction = C4::Context->preference("PatronSelfRegistrationAgeRestriction"); if ( ( $high && ( $age > $high ) ) or ( $age < $low ) ) { push @invalidFields, 'ERROR_age_limitations'; } + if ( $upper_registration_age_restriction && $age > $upper_registration_age_restriction ) { + push @invalidFields, 'ERROR_age_limitations_self_registration'; + } } return \@invalidFields; -- 2.39.5