From e36db00fa15318d49a2c8c5015a44383ee56bc92 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 12 Sep 2024 10:41:18 +0200 Subject: [PATCH] Bug 37902: Make sure filtered_params are converted Previously we only adjusted the attributes that were passed directly, not the ones in 'q' (which is the recommended way now) Signed-off-by: Nick Clemens Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer --- Koha/REST/Plugin/Objects.pm | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm index a6b9ab6c3d..2b1dbbe83c 100644 --- a/Koha/REST/Plugin/Objects.pm +++ b/Koha/REST/Plugin/Objects.pm @@ -209,20 +209,10 @@ controller, and thus shouldn't be called twice in it. } ); - # Call the to_model function by reference, if defined - if ( defined $filtered_params ) { - - # Apply the mapping function to the passed params - $filtered_params = - $result_set->attributes_from_api($filtered_params); - $filtered_params = - $c->build_query_params( $filtered_params, $reserved_params ); - } - + my $query_params; if ( defined $reserved_params->{q} || defined $reserved_params->{query} ) { - $filtered_params //= {}; my @query_params_array; @@ -261,18 +251,12 @@ controller, and thus shouldn't be called twice in it. } } - my $query_params; - if ( scalar(@query_params_array) > 1 ) { $query_params = { '-and' => \@query_params_array }; } else { $query_params = $query_params_array[0]; } - - $filtered_params = - $c->merge_q_params( $filtered_params, $query_params, - $result_set ); } # request sequence id (i.e. 'draw' Datatables parameter) @@ -287,6 +271,20 @@ controller, and thus shouldn't be called twice in it. $c->stash('koha.pagination.base_total' => $result_set->count); $c->stash('koha.pagination.query_params' => $args); + + # Apply the mapping function to the passed params + if ( defined $filtered_params ) { + $filtered_params = + $c->build_query_params( $filtered_params, $reserved_params ); + } + + $filtered_params = + $c->merge_q_params( $filtered_params, $query_params, + $result_set ); + + $filtered_params = + $result_set->attributes_from_api($filtered_params); + $c->dbic_validate_operators( { filtered_params => $filtered_params } ); # Generate the resultset -- 2.39.5