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 <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2021-02-05 10:53:54 +01:00 committed by Tomas Cohen Arazi
parent 6d54d2419f
commit 17b384ee3b
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -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
);
}