From 9ff1f833fc82cc27d76159e001ffe14644c27792 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 5 Feb 2021 10:53:54 +0100 Subject: [PATCH] Bug 27634: Turn off patron self-registration if no default category is set If there is no default category defined in PatronSelfRegistrationDefaultCategory the full feature must be displayed. We already hide the link from the OPAC main page, but the form is still accessible. Test plan (for the whole patch set): 1. Turn on PatronSelfRegistration 2. Don't set PatronSelfRegistrationDefaultCategory 3. Go to the OPAC main page and confirm that the "Register here" link is not displayed 4. Hit opac-memberentry.pl and confirm that you are redirected to the OPAC main page 5. Go to the about page and confirm that you see a warning in the "System information" tab 6. Set PatronSelfRegistrationDefaultCategory to an invalid patron's category 7. Repeat 3, 4, 5 8. Set PatronSelfRegistrationDefaultCategory to a valid patron's category 9. Self-register a patron and confirm it works as expected 10. Edit PatronSelfRegistrationBorrowerUnwantedField and confirm that you cannot remove dateexpiry and categorycode --- opac/opac-memberentry.pl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index 8f105fb5e7..c0e7ddd90b 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -57,12 +57,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -unless ( C4::Context->preference('PatronSelfRegistration') || $borrowernumber ) -{ - print $cgi->redirect("/cgi-bin/koha/opac-main.pl"); - exit; -} - my $action = $cgi->param('action') || q{}; if ( $action eq q{} ) { if ($borrowernumber) { @@ -73,6 +67,16 @@ if ( $action eq q{} ) { } } +my $PatronSelfRegistrationDefaultCategory = C4::Context->preference('PatronSelfRegistrationDefaultCategory'); +my $defaultCategory = Koha::Patron::Categories->find($PatronSelfRegistrationDefaultCategory); +# Having a valid PatronSelfRegistrationDefaultCategory is mandatory +if ( !C4::Context->preference('PatronSelfRegistration') && !$borrowernumber + || ( ( $action eq 'new' || $action eq 'create' ) && !$defaultCategory ) ) +{ + print $cgi->redirect("/cgi-bin/koha/opac-main.pl"); + exit; +} + my $mandatory = GetMandatoryFields($action); my @libraries = Koha::Libraries->search; @@ -96,8 +100,6 @@ if ( defined $min ) { ); } -my $defaultCategory = Koha::Patron::Categories->find(C4::Context->preference('PatronSelfRegistrationDefaultCategory')); - $template->param( action => $action, hidden => GetHiddenFields( $mandatory, $action ), @@ -129,7 +131,7 @@ if ( $action eq 'create' ) { my %borrower = ParseCgiForBorrower($cgi); %borrower = DelEmptyFields(%borrower); - $borrower{categorycode} ||= C4::Context->preference('PatronSelfRegistrationDefaultCategory'); + $borrower{categorycode} ||= $PatronSelfRegistrationDefaultCategory; my @empty_mandatory_fields = (CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) ); my $invalidformfields = CheckForInvalidFields(\%borrower); @@ -238,7 +240,7 @@ if ( $action eq 'create' ) { { borrowernumber => $patron->borrowernumber }, $template, 1, - C4::Context->preference('PatronSelfRegistrationDefaultCategory') + $PatronSelfRegistrationDefaultCategory ); } -- 2.20.1