Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bestpractical/rt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsunnavy <sunnavy@bestpractical.com>2022-09-15 23:21:36 +0300
committersunnavy <sunnavy@bestpractical.com>2022-09-15 23:21:36 +0300
commit7310a291852d3fdb4f351d05e762c4bb5de58907 (patch)
tree21d843e03bffe05f21d21cc83d8d2301a838a948
parente271ef77f806735317dfc6b12726be6970604ae8 (diff)
parent02b9e1efc127e28a13a76d6544d7e21f99e9dd10 (diff)
Merge branch '5.0/add-dashboard-list-to-email-cli' into 5.0-trunk
-rw-r--r--lib/RT/Dashboard/Mailer.pm27
-rw-r--r--sbin/rt-email-dashboards.in17
2 files changed, 35 insertions, 9 deletions
diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
index 5eca55a391..84275ecfa3 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -61,7 +61,7 @@ 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;
@@ -70,6 +70,7 @@ sub MailDashboards {
DryRun => 0,
Time => time,
User => undef,
+ Dashboards => 0,
@_,
);
@@ -78,6 +79,17 @@ sub MailDashboards {
my $from = $self->GetFrom();
$RT::Logger->debug("Sending email from $from");
+ my @dashboards;
+ if( $args{ Dashboards } ) {
+ @dashboards = split(/,/, $args{ Dashboards });
+ $RT::Logger->warning( "Non-numeric dashboard IDs are not permitted" ) if any{ /\D/ } @dashboards;
+ @dashboards = grep { /^\d+$/ } @dashboards;
+ if( @dashboards == 0 ) {
+ $RT::Logger->warning( "--dashboards 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;
@@ -106,6 +118,7 @@ sub MailDashboards {
Subscription => $subscription,
User => $user,
LocalTime => [$hour, $dow, $dom],
+ Dashboards => \@dashboards,
);
my $recipients = $subscription->SubValue('Recipients');
@@ -227,12 +240,20 @@ sub IsSubscriptionReady {
Subscription => undef,
User => undef,
LocalTime => [0, 0, 0],
+ Dashboards => undef,
@_,
);
- return 1 if $args{All};
+ my $subscription = $args{Subscription};
+ my $DashboardId = $subscription->SubValue('DashboardId');
+ my @dashboards = @{ $args{ Dashboards } };
+ if( @dashboards and none { $_ == $DashboardId } @dashboards) {
+ $RT::Logger->info("Dashboard $DashboardId not in list of requested dashboards; skipping");
+ return;
+ }
- my $subscription = $args{Subscription};
+ # Check subscription frequency only once we're sure of the dashboard
+ return 1 if $args{All};
my $counter = $subscription->SubValue('Counter') || 0;
diff --git a/sbin/rt-email-dashboards.in b/sbin/rt-email-dashboards.in
index 469c9208ec..12375a9818 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", "dashboards=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},
+ Dashboards => $opts{dashboards},
+ Opts => \%opts,
);
=head1 NAME
@@ -151,6 +152,10 @@ Display this documentation
Figure out which dashboards would be sent, but don't actually generate or email
any of them
+=item --dashboards DASHBOARD_IDS
+
+Only check specified dashboards(comma-separated IDs).
+
=item --time SECONDS
Instead of using the current time to figure out which dashboards should be