[Rt-commit] rt branch, 4.2/charts-grouped-by-cfs, created. rt-4.1.19-87-ga4440be

Ruslan Zakirov ruz at bestpractical.com
Fri Aug 30 04:00:44 EDT 2013


The branch, 4.2/charts-grouped-by-cfs has been created
        at  a4440beb187a42a572343fe13cf71507aece6127 (commit)

- Log -----------------------------------------------------------------
commit de52084c35d2fe82c20daf82e593baaf5f56ad9f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Aug 30 11:55:36 2013 +0400

    grouping charts by CFs was broken during refactoring
    
    SUBKEY has no dot in it

diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index 4fe6127..9adf7f1 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -754,7 +754,7 @@ sub GenerateCustomFieldFunction {
     my $self = shift;
     my %args = @_;
 
-    my ($name) = ( $args{'SUBKEY'} =~ /^\.\{(.*)\}$/ );
+    my ($name) = ( $args{'SUBKEY'} =~ /^\{(.*)\}$/ );
     my $cf = RT::CustomField->new( $self->CurrentUser );
     $cf->Load($name);
     unless ( $cf->id ) {

commit 8357a8150555496eea08af45b27078745a6ff277
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Aug 30 11:57:18 2013 +0400

    we need CustomFieldLookupType in Report::Tickets::Entry
    
    new generalized code depends on it, otherwise we can not
    load CFs

diff --git a/lib/RT/Report/Tickets/Entry.pm b/lib/RT/Report/Tickets/Entry.pm
index 99b8c1d..724c3e5 100644
--- a/lib/RT/Report/Tickets/Entry.pm
+++ b/lib/RT/Report/Tickets/Entry.pm
@@ -98,6 +98,10 @@ sub ObjectType {
     return 'RT::Ticket';
 }
 
+sub CustomFieldLookupType {
+    RT::Ticket->CustomFieldLookupType
+}
+
 sub Query {
     my $self = shift;
 

commit 4185ab40c2c101fea5cba2b71896cd2ca0f8888f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Aug 30 11:59:08 2013 +0400

    quote identifier when we construct queries

diff --git a/lib/RT/Report/Tickets/Entry.pm b/lib/RT/Report/Tickets/Entry.pm
index 724c3e5..a584efd 100644
--- a/lib/RT/Report/Tickets/Entry.pm
+++ b/lib/RT/Report/Tickets/Entry.pm
@@ -127,6 +127,10 @@ sub Query {
             else {
                 ($op, $value) = ('IS', 'NULL');
             }
+            unless ( $field =~ /^[{}\w\.]+$/ ) {
+                $field =~ s/(['\\])/\\$1/g;
+                $field = "'$field'";
+            }
             push @parts, "$field $op $value";
         }
     }

commit a4440beb187a42a572343fe13cf71507aece6127
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Aug 30 12:00:10 2013 +0400

    test charts groupping by custom fields

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 3ec40db..33f24b0 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -837,6 +837,20 @@ sub create_ticket {
         );
     }
 
+    if ( my $cfs = delete $args{'CustomFields'} ) {
+        my $q = RT::Queue->new( RT->SystemUser );
+        $q->Load( $args{'Queue'} );
+        while ( my ($k, $v) = each %$cfs ) {
+            my $cf = $q->CustomField( $k );
+            unless ($cf->id) {
+                RT->Logger->error("Couldn't load custom field $k");
+                next;
+            }
+
+            $args{'CustomField-'. $cf->id} = $v;
+        }
+    }
+
     my $ticket = RT::Ticket->new( RT->SystemUser );
     my ( $id, undef, $msg ) = $ticket->Create( %args );
     Test::More::ok( $id, "ticket created" )
diff --git a/t/charts/group-by-cf.t b/t/charts/group-by-cf.t
new file mode 100644
index 0000000..12296b8
--- /dev/null
+++ b/t/charts/group-by-cf.t
@@ -0,0 +1,70 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+use RT::Ticket;
+
+my $q = RT::Test->load_or_create_queue( Name => 'General' );
+ok $q && $q->id, 'loaded or created queue';
+my $queue = $q->Name;
+
+my $cf = RT::CustomField->new(RT->SystemUser);
+my ($id,$msg) = $cf->Create(Name => 'Test', Type => 'Freeform', MaxValues => '1', Queue => $q->id);
+ok $id, $msg;
+my $cfid = $cf->id;
+
+
+my @tickets = RT::Test->create_tickets(
+    {},
+    { Subject => 't1', Status => 'new', CustomFields => { Test => 'a' } },
+    { Subject => 't2', Status => 'open', CustomFields => { Test => 'b' } },
+);
+
+use_ok 'RT::Report::Tickets';
+
+{
+    my $report = RT::Report::Tickets->new( RT->SystemUser );
+    my %columns = $report->SetupGroupings(
+        Query    => 'Queue = '. $q->id,
+        GroupBy  => ["CF.{$cfid}"], # TODO: CF.{Name} is not supported at the moment
+        Function => ['COUNT'],
+    );
+
+    my @colors = RT->Config->Get("ChartColors");
+    my $expected = {
+        'thead' => [ {
+                'cells' => [
+                    { 'value' => 'Custom field Test', 'type' => 'head' },
+                    { 'rowspan' => 1, 'value' => 'Ticket count', 'type' => 'head', 'color' => $colors[0] },
+                ],
+        } ],
+       'tfoot' => [ {
+            'cells' => [
+                { 'colspan' => 1, 'value' => 'Total', 'type' => 'label' },
+                { 'value' => 2, 'type' => 'value' },
+            ],
+            'even' => 1
+        } ],
+       'tbody' => [
+            {
+                'cells' => [
+                    { 'value' => 'a', 'type' => 'label' },
+                    { 'query' => "(CF.{$cfid} = 'a')", 'value' => '1', 'type' => 'value' },
+                ],
+                'even' => 1
+            },
+            {
+                'cells' => [
+                    { 'value' => 'b', 'type' => 'label' },
+                    { 'query' => "(CF.{$cfid} = 'b')", 'value' => '1', 'type' => 'value' },
+                ],
+                'even' => 0
+            },
+        ]
+    };
+
+    my %table = $report->FormatTable( %columns );
+    is_deeply( \%table, $expected, "basic table" );
+}
+
+done_testing;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list