[Rt-commit] rt branch, 4.4/query-builder-operator-for-null, created. rt-4.4.2-100-gbc6b5be41
? sunnavy
sunnavy at bestpractical.com
Thu Apr 5 10:30:08 EDT 2018
The branch, 4.4/query-builder-operator-for-null has been created
at bc6b5be412e6f2241e9b9d0e0437a85b3b1eb070 (commit)
- Log -----------------------------------------------------------------
commit 605a43bc8fef806b9c3af0da43a28b1e1156508c
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Feb 23 04:19:45 2018 +0800
Set operator to "IS" or "IS NOT" for NULL values
This is actually the old behavior of RT prior to 4.4. In b68c84f0
(Switch to parsing into a parse tree as an IR), related code was deleted
from old place but wasn't re-implemented in the new place.
diff --git a/lib/RT/Interface/Web/QueryBuilder/Tree.pm b/lib/RT/Interface/Web/QueryBuilder/Tree.pm
index d63a16d4b..fe0bee633 100644
--- a/lib/RT/Interface/Web/QueryBuilder/Tree.pm
+++ b/lib/RT/Interface/Web/QueryBuilder/Tree.pm
@@ -213,14 +213,19 @@ sub __LinearizeTree {
$key = "'$key'";
}
my $value = $clause->{Value};
- if ( $clause->{Op} =~ /^IS( NOT)?$/i ) {
+ my $op = $clause->{Op};
+ if ( $value =~ /^NULL$/i && $op =~ /^(!?)=$/ ) {
+ $op = $1 ? 'IS NOT' : 'IS';
+ }
+
+ if ( $op =~ /^IS( NOT)?$/i ) {
$value = 'NULL';
} elsif ( $value !~ /^[+-]?[0-9]+$/ ) {
$value =~ s/(['\\])/\\$1/g;
$value = "'$value'";
}
- $str .= $key ." ". $clause->{Op} . " " . $value;
+ $str .= $key ." ". $op . " " . $value;
}
$str =~ s/^\s+|\s+$//;
commit bc6b5be412e6f2241e9b9d0e0437a85b3b1eb070
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Feb 23 05:44:10 2018 +0800
Test null values in query builder
diff --git a/t/web/query_builder.t b/t/web/query_builder.t
index c00345ade..89e89f570 100644
--- a/t/web/query_builder.t
+++ b/t/web/query_builder.t
@@ -411,4 +411,48 @@ diag "make sure active and inactive statuses generate the correct query";
is getQueryFromForm( $agent ), "Status = '__Inactive__'", "inactive status generated the correct query";
}
+diag "test null values";
+{
+ my $cf = RT::Test->load_or_create_custom_field(
+ Name => 'foo',
+ Type => 'FreeformSingle',
+ Queue => 0,
+ );
+
+ RT::Test->create_tickets(
+ { Queue => 'General' },
+ { Subject => 'ticket bar', 'CustomField-' . $cf->id => 'bar' },
+ { Subject => 'ticket baz', 'CustomField-' . $cf->id => 'baz' },
+ { Subject => 'ticket null' },
+ );
+
+ $agent->get_ok( '/Search/Build.html?NewQuery=1' );
+ $agent->submit_form(
+ form_name => 'BuildQuery',
+ fields => { 'CF.{foo}Op' => '=', 'ValueOfCF.{foo}' => 'NULL', },
+ button => 'DoSearch',
+ );
+
+ $agent->title_is( 'Found 2 tickets', 'found 2 tickets with CF.{foo} IS NULL' );
+ # the other ticket was created before the block
+ $agent->content_contains( 'ticket null', 'has ticket null' );
+ $agent->follow_link_ok( { text => 'Advanced' } );
+ $agent->text_lacks( q[CF.{foo} = 'NULL'] );
+ $agent->text_contains( 'CF.{foo} IS NULL', q["= 'NULL'" is converted to "IS NULL"] );
+
+ $agent->get_ok( '/Search/Build.html?NewQuery=1' );
+ $agent->submit_form(
+ form_name => 'BuildQuery',
+ fields => { 'CF.{foo}Op' => '!=', 'ValueOfCF.{foo}' => 'NULL', },
+ button => 'DoSearch',
+ );
+
+ $agent->title_is( 'Found 2 tickets', 'found 2 ticket with CF.{foo} IS NOT NULL' );
+ $agent->content_contains( 'ticket bar', 'has ticket bar' );
+ $agent->content_contains( 'ticket baz', 'has ticket baz' );
+ $agent->follow_link_ok( { text => 'Advanced' } );
+ $agent->text_lacks( q[CF.{foo} != 'NULL'] );
+ $agent->text_contains( 'CF.{foo} IS NOT NULL', q["!= 'NULL'" is converted to "IS NOT NULL"] );
+}
+
done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list