[Rt-commit] rt branch 5.0/dashboard-test-email-button created. rt-5.0.2-223-g2c2927fa86

BPS Git Server git at git.bestpractical.com
Mon May 16 14:08:06 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/dashboard-test-email-button has been created
        at  2c2927fa86772f024b032f197f639275a571fa20 (commit)

- Log -----------------------------------------------------------------
commit 2c2927fa86772f024b032f197f639275a571fa20
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon May 16 22:04:51 2022 +0800

    Support to manually send dashboard emails for testing on Subscription page

diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
index e95516ab2d..a058e4f7d0 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -70,6 +70,8 @@ sub MailDashboards {
         DryRun => 0,
         Time   => time,
         User   => undef,
+        Test   => 0,
+        Subscription => undef,
         @_,
     );
 
@@ -88,6 +90,10 @@ sub MailDashboards {
         $Users->Limit( FIELD => 'id', VALUE => $user->Id || 0 );
     }
 
+    if ( $args{Subscription} ) {
+        $Users->Limit( FIELD => 'id', VALUE => $args{Subscription}->Object->Id || 0 );
+    }
+
     while (defined(my $user = $Users->Next)) {
         my ($hour, $dow, $dom) = HourDowDomIn($args{Time}, $user->Timezone || RT->Config->Get('Timezone'));
         $hour .= ':00';
@@ -100,7 +106,8 @@ sub MailDashboards {
 
         # look through this user's subscriptions, are any supposed to be generated
         # right now?
-        for my $subscription ($user->Attributes->Named('Subscription')) {
+        my @subscriptions = $args{Subscription} || $user->Attributes->Named('Subscription');
+        for my $subscription (@subscriptions) {
             next unless $self->IsSubscriptionReady(
                 %args,
                 Subscription => $subscription,
@@ -211,7 +218,7 @@ sub MailDashboards {
                 }
             }
 
-            if ($email_success) {
+            if ( $email_success && !$args{Test} ) {
                 my $counter = $subscription->SubValue('Counter') || 0;
                 $subscription->SetSubValues(Counter => $counter + 1)
                     unless $args{DryRun};
@@ -227,10 +234,11 @@ sub IsSubscriptionReady {
         Subscription => undef,
         User         => undef,
         LocalTime    => [0, 0, 0],
+        Test         => 0,
         @_,
     );
 
-    return 1 if $args{All};
+    return 1 if $args{All} || $args{Test};
 
     my $subscription  = $args{Subscription};
 
diff --git a/share/html/Dashboards/Subscription.html b/share/html/Dashboards/Subscription.html
index c5b631c74a..811f47f304 100644
--- a/share/html/Dashboards/Subscription.html
+++ b/share/html/Dashboards/Subscription.html
@@ -291,6 +291,7 @@
   <div class="form-row">
     <div class="col-12">
 % if ($SubscriptionObj) {
+      <& /Elements/Submit, Name => 'SendTestEmail', Label => loc('Send Test Email') &>
       <& /Elements/Submit, Name => "Save", Label => loc('Save Changes') &>
 % } else {
       <& /Elements/Submit, Name => "Save", Label => loc('Subscribe') &>
@@ -463,6 +464,15 @@ if (defined $ARGS{Save}) {
     $UserString = undef;
     $UserField = undef;
     $UserOp = undef;
+} elsif ( $ARGS{SendTestEmail} ) {
+    if ($SubscriptionObj) {
+        require RT::Dashboard::Mailer;
+        RT::Dashboard::Mailer->MailDashboards(
+            Subscription => $SubscriptionObj,
+            Test         => 1,
+        );
+        push @results, loc("Sent test email");
+    }
 }
 
 if ($SubscriptionObj) {

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list