[Rt-commit] rt branch, 4.4/query-builder-operator-for-null, created. rt-4.4.2-100-g0065a2038

? sunnavy sunnavy at bestpractical.com
Thu Mar 22 14:53:10 EDT 2018


The branch, 4.4/query-builder-operator-for-null has been created
        at  0065a2038cd10bbc572d4b86e467677eb99f233a (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 0065a2038cd10bbc572d4b86e467677eb99f233a
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..29edd8af6 100644
--- a/t/web/query_builder.t
+++ b/t/web/query_builder.t
@@ -411,4 +411,51 @@ 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' },
+    );
+
+    my ( $baseurl, $m ) = RT::Test->started_ok;
+    ok( $m->login, 'logged in' );
+
+    $m->get_ok( '/Search/Build.html' );
+    $m->submit_form(
+        form_name => 'BuildQuery',
+        fields    => { 'CF.{foo}Op' => '=', 'ValueOfCF.{foo}' => 'NULL', },
+        button    => 'DoSearch',
+    );
+
+    $m->title_is( 'Found 2 tickets', 'found 2 tickets with CF.{foo} IS NULL' );
+    # the other ticket was created before the block
+    $m->content_contains( 'ticket null', 'has ticket null' );
+    $m->follow_link_ok( { text => 'Advanced' } );
+    $m->text_lacks( q[CF.{foo} = 'NULL'] );
+    $m->text_contains( 'CF.{foo} IS NULL', q["= 'NULL'" is converted to "IS NULL"] );
+
+    $m->get_ok( '/Search/Build.html?NewQuery=1' );
+    $m->submit_form(
+        form_name => 'BuildQuery',
+        fields    => { 'CF.{foo}Op' => '!=', 'ValueOfCF.{foo}' => 'NULL', },
+        button    => 'DoSearch',
+    );
+
+    $m->title_is( 'Found 2 tickets', 'found 2 ticket with CF.{foo} IS NOT NULL' );
+    $m->content_contains( 'ticket bar', 'has ticket bar' );
+    $m->content_contains( 'ticket baz', 'has ticket baz' );
+    $m->follow_link_ok( { text => 'Advanced' } );
+    $m->text_lacks( q[CF.{foo} != 'NULL'] );
+    $m->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