From 876dfc0ba906137db4e54bc3799946c355a1ad1b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 28 Apr 2020 13:09:49 +0200 Subject: [PATCH] Bug 22844: Make the patron's attribute mandatory at the OPAC Test plan: - Set 1+ patron's attribute(s) mandatory - Use the self-registration feature and confirm that you cannot selfreg if the attribute has no value (or empty string) - Same with the modification form (logged in) Signed-off-by: Victor Grousset/tuxayo --- .../bootstrap/en/modules/opac-memberentry.tt | 9 +++++++- opac/opac-memberentry.pl | 21 ++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) 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 35af40224f..616d95eae7 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -907,7 +907,11 @@ [% IF loop.first %][% END %] [% form_id = 'patron-attr-' _ Math.int( Math.rand(1000000) ) %]
  • - + [% IF pa.type.mandatory && pa.type.opac_editable %] + + [% ELSE %] + + [% END %] [% IF pa.type.opac_editable %] [% IF ( pa.type.authorised_value_category ) %] @@ -928,6 +932,9 @@ [% ELSE %] [% END %] + [% IF pa.type.mandatory %] + Required + [% END %] Clear [% IF ( pa.type.repeatable ) %] New diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index faf32e8285..d2b4eb28e6 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -123,7 +123,7 @@ if ( $action eq 'create' ) { %borrower = DelEmptyFields(%borrower); - my @empty_mandatory_fields = CheckMandatoryFields( \%borrower, $action ); + my @empty_mandatory_fields = (CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) ); my $invalidformfields = CheckForInvalidFields(\%borrower); delete $borrower{'password2'}; my $cardnumber_error_code; @@ -259,7 +259,7 @@ elsif ( $action eq 'update' ) { $borrower{borrowernumber} = $borrowernumber; my @empty_mandatory_fields = - CheckMandatoryFields( \%borrower, $action ); + ( CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) ); my $invalidformfields = CheckForInvalidFields(\%borrower); # Send back the data to the template @@ -412,6 +412,20 @@ sub CheckMandatoryFields { return @empty_mandatory_fields; } +sub CheckMandatoryAttributes{ + my ( $borrower, $attributes ) = @_; + + my @empty_mandatory_fields; + + for my $attribute (@$attributes ) { + my $attr = Koha::Patron::Attribute::Types->find($attribute->{code}); + push @empty_mandatory_fields, $attribute->{code} + if $attr && $attr->mandatory && $attribute->{attribute} =~ m|^\s*$|; + } + + return @empty_mandatory_fields; +} + sub CheckForInvalidFields { my $borrower = shift; my @invalidFields; @@ -689,7 +703,8 @@ sub ParsePatronAttributes { } foreach my $code ( keys %{$delete_candidates} ) { - if ( Koha::Patron::Attributes->search({ + if ( not $borrowernumber # self-registration + || Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber, code => $code })->count > 0 ) { push @attributes, { code => $code, attribute => '' } -- 2.26.2