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 <victor@tuxayo.net>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2020-04-28 13:09:49 +02:00
parent f23a4cdda9
commit dc0077b3a1
2 changed files with 26 additions and 4 deletions

View file

@ -907,7 +907,11 @@
[% IF loop.first %]<a name="patron-attr-start-[% pa.type.code | html %]"></a>[% END %]
[% form_id = 'patron-attr-' _ Math.int( Math.rand(1000000) ) %]
<li data-category_code="[% pa.type.category_code | html %]">
<label for="[% form_id | html %]">[% pa.type.description | html %]: </label>
[% IF pa.type.mandatory && pa.type.opac_editable %]
<label for="[% form_id | html %]" class="required">[% pa.type.description | html %]: </label>
[% ELSE %]
<label for="[% form_id | html %]">[% pa.type.description | html %]: </label>
[% END %]
[% IF pa.type.opac_editable %]
<input type="hidden" name="patron_attribute_code" value="[% pa.type.code | html %]" />
[% IF ( pa.type.authorised_value_category ) %]
@ -928,6 +932,9 @@
[% ELSE %]
<textarea rows="2" cols="30" id="[% form_id | html %]" name="patron_attribute_value">[% pa_value | html %]</textarea>
[% END %]
[% IF pa.type.mandatory %]
<span class="required">Required</span>
[% END %]
<a href="#" class="clear-attribute">Clear</a>
[% IF ( pa.type.repeatable ) %]
<a href="#" class="clone-attribute">New</a>

View file

@ -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;
@ -691,7 +705,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 => '' }