Skip to content

Commit 0cc22cc

Browse files
Merge branch '5.0/chart-group-by-watchers-in-perl' into 5.0-trunk
2 parents f5c3058 + 4161e49 commit 0cc22cc

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

lib/RT/Report/Tickets.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ our %GROUPINGS_META = (
192192
Display => sub {
193193
my $self = shift;
194194
my %args = (@_);
195-
if ( $args{FIELD} eq 'id' ) {
195+
# VALUE could be "(no value)" from perl level calculation
196+
if ( $args{FIELD} eq 'id' && ($args{'VALUE'} // '') !~ /\D/ ) {
196197
my $princ = RT::Principal->new( $self->CurrentUser );
197198
$princ->Load( $args{'VALUE'} ) if $args{'VALUE'};
198199
return $self->loc('(no value)') unless $princ->Id;
@@ -855,17 +856,16 @@ sub _DoSearch {
855856
my @values;
856857
if ( $ticket->can($group->{KEY}) ) {
857858
my $method = $group->{KEY};
858-
push @values, @{$ticket->$method->UserMembersObj->ItemsArrayRef};
859+
push @values, map { $_->MemberId } @{$ticket->$method->MembersObj->ItemsArrayRef};
859860
}
860861
elsif ( $group->{KEY} eq 'Watcher' ) {
861-
push @values, @{$ticket->$_->UserMembersObj->ItemsArrayRef} for /Requestor Cc AdminCc/;
862+
push @values, map { $_->MemberId } @{$ticket->$_->MembersObj->ItemsArrayRef} for /Requestor Cc AdminCc/;
862863
}
863864
else {
864865
RT->Logger->error("Unsupported group by $group->{KEY}");
865866
next;
866867
}
867868

868-
@values = map { $_->_Value( $group->{SUBKEY} || 'Name' ) } @values;
869869
@values = $self->loc('(no value)') unless @values;
870870
$value = \@values;
871871
}

t/web/charting.t

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use RT::Test tests => undef, config => 'Set($EnableJSChart, 0);';
66
plan skip_all => 'GD required'
77
unless RT::StaticUtil::RequireModule("GD");
88

9+
my $core_group = RT::Test->load_or_create_group('core team');
10+
911
for my $n (1..7) {
1012
my $ticket = RT::Ticket->new( RT->SystemUser );
1113
my $req = 'root' . ($n % 2) . '@localhost';
@@ -14,6 +16,9 @@ for my $n (1..7) {
1416
Queue => "General",
1517
Owner => "root",
1618
Requestor => $req,
19+
AdminCc => [ $req, $core_group->Id ],
20+
Starts => '2022-12-10 00:00:00',
21+
Started => '2022-12-11 00:00:00',
1722
MIMEObj => MIME::Entity->build(
1823
From => $req,
1924
To => 'rt@localhost',
@@ -77,6 +82,31 @@ $m->warning_like( qr{'Requestor\.Phone' is not a valid grouping for reports} );
7782
is( $m->content_type, "image/png" );
7883
ok( length($m->content), "Has content" );
7984

85+
# Group by AdminCc name
86+
$m->get_ok("/Search/Chart.html?Query=id>0&GroupBy=AdminCc.Name");
87+
$m->content_like( qr{<th[^>]*>AdminCc\s+Name</th>\s*<th[^>]*>Ticket count\s*</th>}, "Grouped by AdminCc" );
88+
$m->content_like( qr{Group: core team\s*</th>\s*<td[^>]*>\s*<a[^>]*>7</a>}, "Found group results in table" );
89+
$m->content_like( qr{root0\@localhost\s*</th>\s*<td[^>]*>\s*<a[^>]*>3</a>}, "Found results in table" );
90+
$m->content_like( qr{<img src="/Search/Chart\?}, "Found image" );
91+
92+
$m->get_ok("/Search/Chart?Query=id>0&GroupBy=AdminCc.Name");
93+
is( $m->content_type, "image/png" );
94+
ok( length( $m->content ), "Has content" );
95+
96+
# Group by AdminCc name and duration, which is calculated in perl instead of db.
97+
$m->get_ok("/Search/Chart.html?Query=id>0&GroupBy=AdminCc.Name&GroupBy=Starts+to+Started.Default");
98+
$m->content_like(
99+
qr{<th[^>]*>AdminCc\s+Name</th>\s*<th[^>]*>Starts to Started Default\s*</th>\s*<th[^>]*>Ticket count\s*</th>},
100+
"Grouped by AdminCc and Starts to Started" );
101+
$m->content_like( qr{Group: core team\s*</th>\s*<th[^>]*>24 hours</th>\s*<td[^>]*>\s*<a[^>]*>7</a>},
102+
"Found group results in table" );
103+
$m->content_like( qr{root0\@localhost\s*</th>\s*<td[^>]*>\s*<a[^>]*>3</a>}, "Found results in table" );
104+
$m->content_like( qr{<img src="/Search/Chart\?}, "Found image" );
105+
106+
$m->get_ok("/Search/Chart?Query=id>0&GroupBy=AdminCc.Name&GroupBy=Starts+to+Started.Default");
107+
is( $m->content_type, "image/png" );
108+
ok( length( $m->content ), "Has content" );
109+
80110
diag "Confirm subnav links use Query param before saved search in session.";
81111

82112
$m->get_ok( "/Search/Chart.html?Query=id>0" );

0 commit comments

Comments
 (0)