From 2be1b0fe108f40407209f1dda7bfbb4475b8265d Mon Sep 17 00:00:00 2001 From: sunnavy Date: Thu, 16 Nov 2023 15:43:23 -0500 Subject: [PATCH 1/2] Avoid duplicates of TicketType/ObjectType criteria for txn searches The duplicates could happen when you navigate pages on txn search result page. --- lib/RT/Interface/Web.pm | 15 ++++++++++----- t/web/search_txns.t | 9 +++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm index 7718e619183..260a646d464 100644 --- a/lib/RT/Interface/Web.pm +++ b/lib/RT/Interface/Web.pm @@ -5806,11 +5806,16 @@ sub PreprocessTransactionSearchQuery { my @limits; if ( $args{ObjectType} eq 'RT::Ticket' ) { - @limits = ( - q{TicketType = 'ticket'}, - qq{ObjectType = '$args{ObjectType}'}, - $args{Query} =~ /^\s*\(.*\)$/ ? $args{Query} : "($args{Query})" - ); + if ( $args{Query} !~ /^TicketType = 'ticket' AND ObjectType = '$args{ObjectType}' AND (.+)/ ) { + @limits = ( + q{TicketType = 'ticket'}, + qq{ObjectType = '$args{ObjectType}'}, + $args{Query} =~ /^\s*\(.*\)$/ ? $args{Query} : "($args{Query})" + ); + } + else { + @limits = $args{Query}; + } } else { # Other ObjectTypes are not supported for now diff --git a/t/web/search_txns.t b/t/web/search_txns.t index bf4ca0b817f..24366e19117 100644 --- a/t/web/search_txns.t +++ b/t/web/search_txns.t @@ -29,9 +29,14 @@ diag "Query builder"; $m->follow_link_ok( { id => 'page-results' } ); $m->title_is('Found 3 transactions'); + $m->get_ok($m->uri . '&RowsPerPage=1'); + $m->follow_link_ok( { text => '2' } ); + $m->follow_link_ok( { text => '3' } ); + + $m->follow_link_ok( { text => 'Edit Search' }, 'Build Query' ); + my $form = $m->form_name('BuildQuery'); + is($form->find_input('Query')->value, qq{TicketType = 'ticket' AND ObjectType = 'RT::Ticket' AND ( TicketId = 1 )}); - $m->back; - $m->form_name('BuildQuery'); $m->field( TypeOp => '=' ); $m->field( ValueOfType => 'Create' ); $m->click('AddClause'); From 863714d30a8e80ccc7f262da9cade5c484059141 Mon Sep 17 00:00:00 2001 From: sunnavy Date: Thu, 16 Nov 2023 16:19:23 -0500 Subject: [PATCH 2/2] Make sure both prefix and suffix of spaces are removed Previously after parsing and reassembling, searches like "... AND ( id > 0 )" were changed to "... AND ( id > 0 )", note that an additional whitespace was added ahead of "id > 0". This commit fixes this issue. --- lib/RT/Interface/Web/QueryBuilder/Tree.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/RT/Interface/Web/QueryBuilder/Tree.pm b/lib/RT/Interface/Web/QueryBuilder/Tree.pm index 59365881da9..2b1f8cb5c12 100644 --- a/lib/RT/Interface/Web/QueryBuilder/Tree.pm +++ b/lib/RT/Interface/Web/QueryBuilder/Tree.pm @@ -297,7 +297,8 @@ sub __LinearizeTree { $str .= $key ." ". $op . " " . $value; } - $str =~ s/^\s+|\s+$//; + $str =~ s/^\s+//; + $str =~ s/\s+$//; push @$list, { NODE => $node,