[Rt-commit] rt branch, 4.4/empty-dashboard-mail, repushed

Shawn Moore shawn at bestpractical.com
Wed Jan 6 16:15:11 EST 2016


The branch 4.4/empty-dashboard-mail was deleted and repushed:
       was 5727088245f60eb5352cccccb2e41734cfcf75c4
       now f8fc426e0b86fbc6fb750c5e8abed3119e46ecaa

1:  5727088 ! 1:  f8fc426 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,
          );
    @@ -157,6 +191,64 @@
      $ShowEmpty      => 0
      $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/MyReminders b/share/html/Elements/MyReminders
    +--- a/share/html/Elements/MyReminders
    ++++ b/share/html/Elements/MyReminders
    +@@
    +     title => loc("My reminders"),
    +     title_href => RT->Config->Get('WebPath') . '/Tools/MyReminders.html' &>
    + 
    +-<& /Elements/ShowReminders &>
    ++<& /Elements/ShowReminders, HasResults => $HasResults &>
    + 
    + </&>
    + 
    + <%init>
    + return unless RT->Config->Get('EnableReminders');
    + </%init>
    ++<%ARGS>
    ++$HasResults => undef
    ++</%ARGS>
    +
    +diff --git a/share/html/Elements/ShowReminders b/share/html/Elements/ShowReminders
    +--- a/share/html/Elements/ShowReminders
    ++++ b/share/html/Elements/ShowReminders
    +@@
    + $targets->FromSQL( "ReferredToBy = " . $reminder->id );
    + 
    + if ( my $ticket= $targets->First ) {
    ++    $$HasResults++ if $HasResults;
    + </%PERL>
    + <tr class="<% $i%2 ? 'oddline' : 'evenline' %>">
    + <td class="collection-as-table">
    +@@
    + 
    + $reminders->FromSQL($tsql);
    + $reminders->OrderBy( FIELD => 'Due', ORDER => 'ASC' );
    ++
    ++# 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);
    + </%INIT>
    + 
    + <%ARGS>
    + $OnlyOverdue => 0
    ++$HasResults => undef
      </%ARGS>
     
     diff --git a/share/html/Elements/ShowSearch b/share/html/Elements/ShowSearch
    @@ -180,6 +272,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,7 +306,7 @@
     +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');
    @@ -209,12 +318,18 @@
     +    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');
    @@ -246,7 +361,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;
    -+    like($content, qr/highest priority tickets I own/);
    ++    ok($content =~ qr/highest priority tickets I own/);
     +}
     +
     +RT::Test->create_ticket(
    @@ -265,9 +380,47 @@
     +
     +    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