From 2e7e5c465916f54c0158872408b730a3369a795e 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 Signed-off-by: Katrin Fischer (cherry picked from commit 9ea82b05d59d6430cffa448d94be076f3fe20f1c) Signed-off-by: Lucas Gass --- .../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 e430f5e45b..dde1efaf4d 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 %] @@ -554,7 +557,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 3e75eeebde..7ee45c5eed 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -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'));