[Rt-commit] rt branch 5.0/add-dashboard-list-to-email-cli created. rt-5.0.3-119-gbc159ab564

BPS Git Server git at git.bestpractical.com
Wed Sep 14 14:01:17 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/add-dashboard-list-to-email-cli has been created
        at  bc159ab564b771ce5925df0161012a56f9a5c55e (commit)

- Log -----------------------------------------------------------------
commit bc159ab564b771ce5925df0161012a56f9a5c55e
Author: Jason Crome <jcrome at bestpractical.com>
Date:   Wed Sep 14 10:00:48 2022 -0400

    Pass optional list of dashboard IDs to email

diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
index 5eca55a391..027cdb3911 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -61,15 +61,17 @@ use RT::Interface::Web;
 use File::Temp 'tempdir';
 use HTML::Scrubber;
 use URI::QueryParam;
-use List::MoreUtils 'uniq';
+use List::MoreUtils qw( any none uniq );
 
 sub MailDashboards {
     my $self = shift;
     my %args = (
-        All    => 0,
-        DryRun => 0,
-        Time   => time,
-        User   => undef,
+        All       => 0,
+        DryRun    => 0,
+        Time      => time,
+        User      => undef,
+        Recipient => undef,
+        Dashboard => 0,
         @_,
     );
 
@@ -78,6 +80,17 @@ sub MailDashboards {
     my $from = $self->GetFrom();
     $RT::Logger->debug("Sending email from $from");
 
+    my @dashboards;
+    if( $args{ Dashboard } ) {
+        @dashboards = split(/,/, $args{ Dashboard });
+        $RT::Logger->info( "Non-numeric dashboard IDs are not permitted" ) if any{ $_ !~ /^\d+$/ } @dashboards;
+        @dashboards = grep { $_ =~ /^\d+$/ } @dashboards;
+        if( @dashboards == 0 ) {
+            $RT::Logger->info( "--dashboard option given but no valid dashboard IDs provided; exiting" );
+            return;
+        }
+    }
+
     # look through each user for her subscriptions
     my $Users = RT::Users->new(RT->SystemUser);
     $Users->LimitToPrivileged;
@@ -193,7 +206,6 @@ sub MailDashboards {
                     }
 
                     $currentuser->{'LangHandle'} = RT::I18N->get_handle($lang);
-
                     $self->SendDashboard(
                         %args,
                         CurrentUser  => $currentuser,
@@ -201,6 +213,7 @@ sub MailDashboards {
                         Email        => $email,
                         Subscription => $subscription,
                         From         => $from,
+                        Dashboard    => \@dashboards,
                     )
                 };
                 if ( $@ ) {
@@ -299,6 +312,7 @@ sub SendDashboard {
         Email        => undef,
         Subscription => undef,
         DryRun       => 0,
+        Dashboard    => undef,
         @_,
     );
 
@@ -309,6 +323,11 @@ sub SendDashboard {
     my $rows = $subscription->SubValue('Rows');
 
     my $DashboardId = $subscription->SubValue('DashboardId');
+    my @dashboards  = $args{ Dashboard };
+    if( @dashboards and none { $_ == $DashboardId } @dashboards) {
+        $RT::Logger->info("Dashboard $DashboardId not in list of requested dashboards; skipping");
+        return;
+    }
 
     my $dashboard = RT::Dashboard->new($currentuser);
     my ($ok, $msg) = $dashboard->LoadById($DashboardId);
diff --git a/sbin/rt-email-dashboards.in b/sbin/rt-email-dashboards.in
index 469c9208ec..d72e92b65c 100644
--- a/sbin/rt-email-dashboards.in
+++ b/sbin/rt-email-dashboards.in
@@ -70,7 +70,7 @@ BEGIN { # BEGIN RT CMD BOILERPLATE
 my %opts;
 use Getopt::Long;
 GetOptions( \%opts,
-    "help|h", "dryrun", "time=i", "epoch=i", "all", "log=s", "user=s"
+    "help|h", "dryrun", "time=i", "epoch=i", "all", "log=s", "user=s", "dashboard=s"
 );
 
 if ($opts{'help'}) {
@@ -100,11 +100,12 @@ RT::Init();
 
 require RT::Dashboard::Mailer;
 RT::Dashboard::Mailer->MailDashboards(
-    All    => $opts{all},
-    DryRun => $opts{dryrun},
-    Time   => ($opts{time} || $opts{epoch} || time), # epoch is the old-style
-    User   => $opts{user},
-    Opts   => \%opts,
+    All       => $opts{all},
+    DryRun    => $opts{dryrun},
+    Time      => ($opts{time} || $opts{epoch} || time), # epoch is the old-style
+    User      => $opts{user},
+    Dashboard => $opts{dashboard},
+    Opts      => \%opts,
 );
 
 =head1 NAME
@@ -151,6 +152,12 @@ Display this documentation
 Figure out which dashboards would be sent, but don't actually generate or email
 any of them
 
+=item --dashboard DASHBOARD_IDS
+
+A comma-separated list of dashboard IDs to send emails for. Only dashboards in
+this list will be sent. Non-integer dashboard IDs will be skipped, and if all
+IDs are invalid, the script will abort.
+
 =item --time SECONDS
 
 Instead of using the current time to figure out which dashboards should be

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list