From 54dba26d5e08efe83dcc6857667968686b155466 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 --- .../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 c12e44c388..69191fedef 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -214,6 +214,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 %] @@ -553,7 +556,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 f647234691..bfc40d3e13 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -285,6 +285,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.34.1