[Rt-commit] rt branch, 4.4/empty-dashboard-mail, repushed
Shawn Moore
shawn at bestpractical.com
Tue Dec 22 20:32:53 EST 2015
The branch 4.4/empty-dashboard-mail was deleted and repushed:
was cc17ef629c5a1a5b8224f6f465cf311bf30da4ef
now 5727088245f60eb5352cccccb2e41734cfcf75c4
1: cc17ef6 ! 1: 5727088 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 = undef;
++ my $HasResults = 0;
+
my $content = RunComponent(
'/Dashboards/Render.html',
@@ -20,37 +20,14 @@
+ HasResults => \$HasResults,
);
-+ 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 ($subscription->SubValue('SuppressIfEmpty') && !$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
@@ -142,8 +119,8 @@
--- a/share/html/Dashboards/Subscription.html
+++ b/share/html/Dashboards/Subscription.html
@@
- <input name="Recipient" id="Recipient" size="30" value="<%$fields{Recipient} ? $fields{Recipient} : ''%>" />
- <div class="hints"><% loc("Leave blank to send to your current email address ([_1])", $session{'CurrentUser'}->EmailAddress) %></div>
+ % }
+ </select>
</td></tr>
+
+<tr><td align="right"><input type="checkbox" id="SuppressIfEmpty" name="SuppressIfEmpty" value="1" <% $fields{'SuppressIfEmpty'} ? 'checked="checked"' : "" |n %> /></td>
@@ -153,9 +130,9 @@
+
</table>
</&>
- </td>
-@@
- Recipient => '',
+
+@@
+ Recipients => { Users => [], Groups => [] },
Fow => 1,
Counter => 0,
+ SuppressIfEmpty => 0,
@@ -166,17 +143,6 @@
diff --git a/share/html/Elements/CollectionList b/share/html/Elements/CollectionList
--- 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,
@@ -192,19 +158,6 @@
$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
@@ -227,23 +180,6 @@
+$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
@@ -261,7 +197,7 @@
+ok( $m->login, 'logged in' );
+
+sub create_dashboard {
-+ my ($name, $suppress_if_empty, $assets) = @_;
++ my ($name, $suppress_if_empty) = @_;
+
+ # first, create and populate a "suppress if empty" dashboard
+ $m->get_ok('/Dashboards/Modify.html?Create=1');
@@ -273,18 +209,12 @@
+ my $form = $m->form_name('Dashboard-Searches-body');
+ my @input = $form->find_input('Searches-body-Available');
+
-+ 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;
++ 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');
+
+ $m->follow_link_ok( { text => 'Subscription' } );
+ $m->form_name('SubscribeDashboard');
@@ -316,7 +246,7 @@
+ 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;
-+ ok($content =~ qr/highest priority tickets I own/);
++ like($content, qr/highest priority tickets I own/);
+}
+
+RT::Test->create_ticket(
@@ -335,47 +265,9 @@
+
+ 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!/);
++ like($content, qr/highest priority tickets I own/);
++ like($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