From 5ceee28d3cea182a9bc4021209362faf86d05a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=A4is=C3=A4?= Date: Thu, 1 Aug 2024 08:46:09 +0300 Subject: [PATCH] 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 Signed-off-by: Baptiste Wojtkowski Signed-off-by: Martin Renvoize --- .../prog/en/modules/members/memberentrygen.tt | 5 ++++- members/memberentry.pl | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 8ec87ce6981..2706777bff4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -217,6 +217,9 @@ legend.collapsed i.fa.fa-caret-down::before { [% IF ( ERROR_cannot_delete_guarantor ) %]
  • Cannot delete guarantor(s). A child patron needs a guarantor.
  • [% END %] + [% IF ( ERROR_invalid_relationship ) %] +
  • Guarantor relationship is invalid.
  • + [% END %] [% END %] @@ -556,7 +559,7 @@ legend.collapsed i.fa.fa-caret-down::before { [% END %] [% END %] - [% UNLESS mandatoryrelationship %] + [% IF mandatoryrelationship %] Required [% END %] diff --git a/members/memberentry.pl b/members/memberentry.pl index 2227df425fb..c3085749710 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -290,6 +290,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')); -- 2.47.0