Skip to content

Commit

Permalink
Merge branch '5.0/refactor-preprocess-txn-search-query' into 5.0-trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrandtbuffalo committed Apr 10, 2024
2 parents c96bd2f + ef6874a commit 362287f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
17 changes: 16 additions & 1 deletion lib/RT/Interface/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5873,10 +5873,25 @@ sub PreprocessTransactionSearchQuery {
my @limits;
if ( $args{ObjectType} eq 'RT::Ticket' ) {
if ( $args{Query} !~ /^TicketType = 'ticket' AND ObjectType = '$args{ObjectType}' AND (.+)/ ) {
require RT::Interface::Web::QueryBuilder::Tree;
my $tree = RT::Interface::Web::QueryBuilder::Tree->new;
my @results = $tree->ParseSQL(
Query => $args{Query},
CurrentUser => $session{CurrentUser},
Class => 'RT::Transactions',
);

# Errors will be handled in FromSQL later, so it's safe to simply return here
return $args{Query} if @results;

if ( lc( $tree->getNodeValue // '' ) eq 'or' ) {
$args{Query} = "( $args{Query} )";
}

@limits = (
q{TicketType = 'ticket'},
qq{ObjectType = '$args{ObjectType}'},
$args{Query} =~ /^\s*\(.*\)$/ ? $args{Query} : "($args{Query})"
$args{Query},
);
}
else {
Expand Down
20 changes: 20 additions & 0 deletions t/transaction/search.t
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,24 @@ is( $txns->Count, 1, 'Found the txn with id limit' );
$txns->FromSQL("id > 10000");
is( $txns->Count, 0, 'No txns with big ids yet' );

diag 'Test HTML::Mason::Commands::PreprocessTransactionSearchQuery';

my %processed = (
q{Type = 'Set'} => q{TicketType = 'ticket' AND ObjectType = 'RT::Ticket' AND Type = 'Set'},
q{Type = 'Set' OR Type = 'Correspond'} =>
q{TicketType = 'ticket' AND ObjectType = 'RT::Ticket' AND ( Type = 'Set' OR Type = 'Correspond' )},
q{( Type = 'Set' ) OR ( Type = 'Correspond' )} =>
q{TicketType = 'ticket' AND ObjectType = 'RT::Ticket' AND ( ( Type = 'Set' ) OR ( Type = 'Correspond' ) )},
q{Type = 'Set' AND Field = 'Status'} =>
q{TicketType = 'ticket' AND ObjectType = 'RT::Ticket' AND Type = 'Set' AND Field = 'Status'},
q{( Type = 'Set' AND Field = 'Status' ) OR ( Type = 'Correspond' )} =>
q{TicketType = 'ticket' AND ObjectType = 'RT::Ticket' AND ( ( Type = 'Set' AND Field = 'Status' ) OR ( Type = 'Correspond' ) )},
);

local $HTML::Mason::Commands::session{CurrentUser} = RT->SystemUser;
for my $query ( sort keys %processed ) {
is( HTML::Mason::Commands::PreprocessTransactionSearchQuery( Query => $query ),
$processed{$query}, "Processed query: $query" );
}

done_testing;
2 changes: 1 addition & 1 deletion t/web/search_txns.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ diag "Query builder";

$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 )});
is($form->find_input('Query')->value, qq{TicketType = 'ticket' AND ObjectType = 'RT::Ticket' AND TicketId = 1});

$m->field( TypeOp => '=' );
$m->field( ValueOfType => 'Create' );
Expand Down

0 comments on commit 362287f

Please sign in to comment.