From 17b384ee3bbe212dfaf5440926d6a02fb0cc6b5e 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 Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- 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 f5a32db85a..56743e97d8 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 ( $borrowernumber && ( $action eq 'create' || $action eq 'new' ) ) { print $cgi->redirect("/cgi-bin/koha/opac-main.pl"); @@ -78,6 +72,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 $params = {}; @@ -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 ), @@ -128,7 +130,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); @@ -251,7 +253,7 @@ if ( $action eq 'create' ) { { borrowernumber => $patron->borrowernumber }, $template, 1, - C4::Context->preference('PatronSelfRegistrationDefaultCategory') + $PatronSelfRegistrationDefaultCategory ); } -- 2.39.5