[Rt-commit] rt branch, 4.4/empty-dashboard-mail, repushed
Shawn Moore
shawn at bestpractical.com
Wed Dec 9 18:15:54 EST 2015
The branch 4.4/empty-dashboard-mail was deleted and repushed:
was 4bb34548decbad6230ee073a123d06431b4766ca
now cc17ef629c5a1a5b8224f6f465cf311bf30da4ef
1: 4bb3454 ! 1: cc17ef6 Let users choose to suppress dashboards with no results
@@ -9,7 +9,7 @@
local $HTML::Mason::Commands::session{CurrentUser} = $currentuser;
local $HTML::Mason::Commands::r = RT::Dashboard::FakeRequest->new;
-+ my $HasResults = 0;
++ my $HasResults = undef;
+
my $content = RunComponent(
'/Dashboards/Render.html',
@@ -20,14 +20,37 @@
+ HasResults => \$HasResults,
);
-+ if ($subscription->SubValue('SuppressIfEmpty') && !$HasResults) {
-+ $RT::Logger->debug("Not sending because there are no results and the subscription has SuppressIfEmpty");
-+ return;
++ if ($subscription->SubValue('SuppressIfEmpty')) {
++ # undef means there were no searches, so we should still send it (it's just portlets)
++ # 0 means there was at least one search and none had any result, so we should suppress it
++ if (defined($HasResults) && !$HasResults) {
++ $RT::Logger->debug("Not sending because there are no results and the subscription has SuppressIfEmpty");
++ return;
++ }
+ }
+
if ( RT->Config->Get('EmailDashboardRemove') ) {
for ( RT->Config->Get('EmailDashboardRemove') ) {
$content =~ s/$_//g;
+
+diff --git a/share/html/Dashboards/Elements/ShowPortlet/component b/share/html/Dashboards/Elements/ShowPortlet/component
+--- a/share/html/Dashboards/Elements/ShowPortlet/component
++++ b/share/html/Dashboards/Elements/ShowPortlet/component
+@@
+ $Portlet
+ $Rows => 20
+ $Preview => 0
++$HasResults
+ </%args>
+ <%init>
+ my $full_path = $Portlet->{path};
+@@
+ % if (!$allowed) {
+ % $m->out( $m->interp->apply_escapes( loc("Invalid portlet [_1]", $path), "h" ) );
+ % } else {
+-% $m->comp($full_path);
++% $m->comp($full_path, HasResults => $HasResults);
+ % }
diff --git a/share/html/Dashboards/Elements/ShowPortlet/dashboard b/share/html/Dashboards/Elements/ShowPortlet/dashboard
--- a/share/html/Dashboards/Elements/ShowPortlet/dashboard
@@ -144,6 +167,17 @@
--- a/share/html/Elements/CollectionList
+++ b/share/html/Elements/CollectionList
@@
+ $Collection->FromSQL($Query);
+ }
+
++# flip HasResults from undef to 0 to indicate there was a search, so
++# dashboard mail can be suppressed if there are no results
++$$HasResults = 0 if $HasResults && !defined($$HasResults);
++
+ $TotalFound = $Collection->CountAll() unless defined $TotalFound;
+ return '' if !$TotalFound && !$ShowEmpty;
+
+@@
Warning => $warning,
Classes => $Classes,
);
@@ -158,6 +192,19 @@
$Query => 0
+$HasResults => undef
</%ARGS>
+
+diff --git a/share/html/Elements/MyAssets b/share/html/Elements/MyAssets
+--- a/share/html/Elements/MyAssets
++++ b/share/html/Elements/MyAssets
+@@
+ %# those contributions and any derivatives thereof.
+ %#
+ %# END BPS TAGGED BLOCK }}}
+-<& /User/Elements/AssetList, User => $session{'CurrentUser'}->UserObj, Roles => [qw(HeldBy)], Title => loc('My Assets') &>
++<& /User/Elements/AssetList, User => $session{'CurrentUser'}->UserObj, Roles => [qw(HeldBy)], Title => loc('My Assets'), HasResults => $HasResults &>
++<%ARGS>
++$HasResults => undef
++</%ARGS>
diff --git a/share/html/Elements/ShowSearch b/share/html/Elements/ShowSearch
--- a/share/html/Elements/ShowSearch
@@ -180,6 +227,23 @@
+$HasResults => undef
</%ARGS>
+diff --git a/share/html/User/Elements/AssetList b/share/html/User/Elements/AssetList
+--- a/share/html/User/Elements/AssetList
++++ b/share/html/User/Elements/AssetList
+@@
+ Order => 'ASC',
+ Format => $Format,
+ AllowSorting => 0,
++ HasResults => $HasResults,
+ &>
+ </&>
+ <%args>
+ $User
+ $Title
+ @Roles
++$HasResults => undef
+ </%args>
+
diff --git a/t/mail/dashboard-empty.t b/t/mail/dashboard-empty.t
new file mode 100644
--- /dev/null
@@ -197,25 +261,31 @@
+ok( $m->login, 'logged in' );
+
+sub create_dashboard {
-+ my ($name, $suppress_if_empty) = @_;
++ my ($name, $suppress_if_empty, $assets) = @_;
+
+ # first, create and populate a "suppress if empty" dashboard
+ $m->get_ok('/Dashboards/Modify.html?Create=1');
+ $m->form_name('ModifyDashboard');
+ $m->field( 'Name' => $name );
+ $m->click_button( value => 'Create' );
-+
++
+ $m->follow_link_ok( { text => 'Content' } );
+ my $form = $m->form_name('Dashboard-Searches-body');
+ my @input = $form->find_input('Searches-body-Available');
-+
-+ my ($dashboards_component) =
-+ map { ( $_->possible_values )[1] }
-+ grep { ( $_->value_names )[1] =~ /My Tickets/ } @input;
-+ $form->value( 'Searches-body-Available' => $dashboards_component );
-+ $m->click_button( name => 'add' );
-+ $m->content_contains('Dashboard updated');
-+
++
++ my $add_component = sub {
++ my $name = shift;
++ my ($dashboards_component) =
++ map { ( $_->possible_values )[1] }
++ grep { ( $_->value_names )[1] =~ $name } @input;
++ $form->value( 'Searches-body-Available' => $dashboards_component );
++ $m->click_button( name => 'add' );
++ $m->content_contains('Dashboard updated');
++ };
++
++ $add_component->('My Tickets') unless $assets;
++ $add_component->('MyAssets') if $assets;
++
+ $m->follow_link_ok( { text => 'Subscription' } );
+ $m->form_name('SubscribeDashboard');
+ $m->field( 'Frequency' => 'daily' );
@@ -232,7 +302,7 @@
+diag 'no mail since the dashboard is suppressed if empty' if $ENV{'TEST_VERBOSE'};
+{
+ RT::Dashboard::Mailer->MailDashboards(All => 1);
-+
++
+ my @mails = RT::Test->fetch_caught_mails;
+ is @mails, 0, "got no dashboard mail because the dashboard is empty";
+}
@@ -242,11 +312,11 @@
+diag 'one mail since one of two dashboards is suppressed if empty' if $ENV{'TEST_VERBOSE'};
+{
+ RT::Dashboard::Mailer->MailDashboards(All => 1);
-+
++
+ my @mails = RT::Test->fetch_caught_mails;
+ is @mails, 1, "got a dashboard mail from the always-send dashboard";
+ my $content = parse_mail( $mails[0] )->bodyhandle->as_string;
-+ like($content, qr/highest priority tickets I own/);
++ ok($content =~ qr/highest priority tickets I own/);
+}
+
+RT::Test->create_ticket(
@@ -259,15 +329,53 @@
+diag 'two mails since both dashboards now have results' if $ENV{'TEST_VERBOSE'};
+{
+ RT::Dashboard::Mailer->MailDashboards(All => 1);
-+
++
+ my @mails = RT::Test->fetch_caught_mails;
+ is @mails, 2, "got a dashboard mail from the always-send dashboard";
+
+ for my $mail (@mails) {
+ my $content = parse_mail( $mail )->bodyhandle->as_string;
-+ like($content, qr/highest priority tickets I own/);
-+ like($content, qr/a search result!/);
++ ok($content =~ qr/highest priority tickets I own/);
++ ok($content =~ qr/a search result!/);
+ }
++}
++
++create_dashboard('My Assets', 1, 1);
++
++diag 'two mails since no asset yet' if $ENV{'TEST_VERBOSE'};
++{
++ RT::Dashboard::Mailer->MailDashboards(All => 1);
++
++ my @mails = RT::Test->fetch_caught_mails;
++ is @mails, 2, "got 2 dashboard mails";
++
++ for my $mail (@mails) {
++ my $content = parse_mail( $mail )->bodyhandle->as_string;
++ ok($content =~ qr/highest priority tickets I own/);
++ ok($content =~ qr/a search result!/);
++ }
++}
++
++my $asset = RT::Asset->new( RT->SystemUser );
++my ($ok, $msg) = $asset->Create(
++ Catalog => 'General assets',
++ HeldBy => 'root at localhost',
++ Description => 'a computer asset',
++);
++ok($ok, $msg);
++
++{
++ RT::Dashboard::Mailer->MailDashboards(All => 1);
++
++ my @mails = RT::Test->fetch_caught_mails;
++ is @mails, 3, "got 3 dashboard mails";
++ my @contents = map { parse_mail( $_ )->bodyhandle->as_string } @mails;
++
++ ok($contents[0] =~ qr/highest priority tickets I own/);
++ ok($contents[0] =~ qr/a search result!/);
++ ok($contents[1] =~ qr/highest priority tickets I own/);
++ ok($contents[1] =~ qr/a search result!/);
++ ok($contents[2] =~ qr/a computer asset/);
+}
+
+undef $m;
More information about the rt-commit
mailing list