Bug 37528: check if selected relationship is valid

This patch checks if the selected relationship is valid before trying to save the patron record.
It takes the list of valid relationships from borrowerRelationships syspref and checks if the selected relationship is in the list.

Also this patch fixes relationship field required message when BorrowerMandatoryField is not set.
The required message is shown when adding the guarantee from guarantor's detail page.

Test plan:
1) Add at least one option to borrowerRelationships syspref.
2) Leave the relationship unchecked from BorrowerMandatoryField syspref.
3) Create a new guarantee patron.
4) Add a guarantor to the guarantee patron.
5) Leave the relationship field empty and try to save the patron record.
6) Notice the 500 error page.
7) Apply the patch.
8) Repeat steps 3-5.
9) Notice the error message "Guarantor relationship is invalid".

Sponsored-by: Koha-Suomi Oy
Signed-off-by: Olivier V <olivier.vezina@inLibro.com>
Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 9ea82b05d5)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Johanna Räisä 2024-08-01 08:46:09 +03:00 committed by Lucas Gass
parent b99b51deef
commit 2e7e5c4659
2 changed files with 20 additions and 1 deletions

View File

@ -217,6 +217,9 @@ legend.collapsed i.fa.fa-caret-down::before {
[% IF ( ERROR_cannot_delete_guarantor ) %]
<li id="ERROR_cannot_delete_guarantor">Cannot delete guarantor(s). A child patron needs a guarantor.</li>
[% END %]
[% IF ( ERROR_invalid_relationship ) %]
<li id="ERROR_invalid_relationship">Guarantor relationship is invalid.</li>
[% END %]
</ul>
</div>
[% END %]
@ -554,7 +557,7 @@ legend.collapsed i.fa.fa-caret-down::before {
[% END %]
[% END %]
</select>
[% UNLESS mandatoryrelationship %]
[% IF mandatoryrelationship %]
<span class="required">Required</span>
[% END %]
</li>

View File

@ -289,6 +289,22 @@ foreach my $guarantor (@guarantors) {
}
}
my @valid_relationships = split(/\|/, C4::Context->preference('borrowerRelationship'), -1);
if (@valid_relationships) {
my @new_guarantor_id = $input->multi_param('new_guarantor_id');
my @new_guarantor_relationship = $input->multi_param('new_guarantor_relationship');
for ( my $i = 0 ; $i < scalar @new_guarantor_id; $i++ ) {
my $guarantor_id = $new_guarantor_id[$i];
my $relationship = $new_guarantor_relationship[$i];
next unless $guarantor_id;
unless ( grep { $_ eq $relationship } @valid_relationships ) {
push @errors, 'ERROR_invalid_relationship';
}
}
}
###############test to take the right zipcode, country and city name ##############
# set only if parameter was passed from the form
$newdata{'city'} = $input->param('city') if defined($input->param('city'));