From 2e8a9bd95d44c3a8dd7728c0dce841467152ad17 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 1 May 2024 18:19:42 +0000 Subject: [PATCH] Bug 35929: Don't record a change for empty fields submitted in patron form This is reminiscent of bug 36159 - when a field is submitted as empty, and null in the DB we need to reject this as a change. I tried to copy the logic from that bug, as well as deleting submitted changes for hidden fields (from html manipulation) This should be tested extensively. One note: If you submit a valid change request, then submit a second with no change the second will be ignored, but the first will remain. i.e. if you change your name from 'Nick' to 'Nack' - then realize your typo you cannot submit a new request to change it back untl the initial request is cleared To test: 1 - Play with PatronSelfModificationBorrowerUnwantedField and PatronSelfModificationMandatory field to have some fields set 2 - Add a patron attribute, or several, that are editable in the OPAC 3 - Try submitting a form with no changes, note a modification requets is submitted 4 - Approve the request 5 - Apply patch, restart all 6 - Try submitted a blank request, you are notified there were no changes 7 - Try to force an unwanted field via html modification 8 - No changes reported 9 - Confirm attributes changes are successful 10 - After a successful request, try submitting a blank request 11 - Note no changes are recorded, but the initial request is still active Signed-off-by: Lucas Gass Signed-off-by: Jonathan Druart Signed-off-by: Katrin Fischer (cherry picked from commit cf4a3667cbeb4dbb6b7dd74fd30a3cacca540603) Signed-off-by: Fridolin Somers (cherry picked from commit 1a898d94649f13e76e094c14ad41395f2bd19c9a) Signed-off-by: Lucas Gass --- opac/opac-memberentry.pl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index 25038ae6a8..f3ecf05821 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -336,7 +336,7 @@ elsif ( $action eq 'update' ) { $borrower_changes{'changed_fields'} = join ',', keys %borrower_changes; my $extended_attributes_changes = FilterUnchangedAttributes( $borrowernumber, $attributes ); - if ( %borrower_changes || scalar @{$extended_attributes_changes} > 0 ) { + if ( $borrower_changes{'changed_fields'} || scalar @{$extended_attributes_changes} > 0 ) { ( $template, $borrowernumber, $cookie ) = get_template_and_user( { template_name => "opac-memberentry-update-submitted.tt", @@ -579,10 +579,8 @@ sub DelUnchangedFields { foreach my $key ( keys %new_data ) { - next if defined($new_data{$key}) xor defined($current_data->{$key}); - if ( !defined($new_data{$key}) || $current_data->{$key} eq $new_data{$key} || $hidden_fields->{$key} ) { - delete $new_data{$key}; - } + next if ( ($new_data{$key} || $current_data->{$key}) && ( $new_data{$key} ne $current_data->{$key} ) && !($hidden_fields->{$key}) ); + delete $new_data{$key}; } return %new_data; -- 2.39.5