[Rt-commit] rt branch, 4.0/delete-subscriptions-in-dashboard-deletion, created. rt-4.0.5-82-gffc34cd

? sunnavy sunnavy at bestpractical.com
Tue Mar 13 22:09:24 EDT 2012


The branch, 4.0/delete-subscriptions-in-dashboard-deletion has been created
        at  ffc34cd23b13a981ab363bff47b8be2b6cab45fd (commit)

- Log -----------------------------------------------------------------
commit 470ba297766e752301167668b662e218b92245fd
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Mar 14 08:57:57 2012 +0800

    delete subscriptions automatically when deleting dashboards

diff --git a/lib/RT/Dashboard.pm b/lib/RT/Dashboard.pm
index 14ffa6a..2e2bbc4 100644
--- a/lib/RT/Dashboard.pm
+++ b/lib/RT/Dashboard.pm
@@ -454,6 +454,36 @@ sub CurrentUserCanCreateAny {
     return 0;
 }
 
+=head2 Delete
+
+Deletes the dashboard and related subscriptions.
+Returns a tuple of status and message, where status is true upon success.
+
+=cut
+
+sub Delete {
+    my $self = shift;
+    my $id = $self->id;
+    my ( $status, $msg ) = $self->SUPER::Delete(@_);
+    if ( $status ) {
+        # delete all the subscriptions
+        my $subscriptions = RT::Attributes->new( RT->SystemUser );
+        $subscriptions->Limit(
+            FIELD => 'Name',
+            VALUE => 'Subscription',
+        );
+        $subscriptions->Limit(
+            FIELD => 'Description',
+            VALUE => "Subscription to dashboard $id",
+        );
+        while ( my $subscription = $subscriptions->Next ) {
+            $subscription->Delete();
+        }
+    }
+
+    return ( $status, $msg );
+}
+
 RT::Base->_ImportOverlays();
 
 1;

commit ffc34cd23b13a981ab363bff47b8be2b6cab45fd
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Mar 14 10:06:02 2012 +0800

    update tests as now subscriptions are cleaned up automaticlaly

diff --git a/t/mail/dashboards.t b/t/mail/dashboards.t
index 7a7a54c..00cfc6a 100644
--- a/t/mail/dashboards.t
+++ b/t/mail/dashboards.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 187;
+use RT::Test tests => 181;
 use Test::Warn;
 use RT::Dashboard::Mailer;
 
@@ -138,17 +138,6 @@ sub delete_dashboard { # {{{
     ok($ok, $msg);
 } # }}}
 
-sub delete_subscriptions { # {{{
-    my $subscription_id = shift;
-    # delete the dashboard and make sure we get exactly one subscription failure
-    # notice
-    my $user = RT::User->new(RT->SystemUser);
-    $user->Load('root');
-    for my $subscription ($user->Attributes->Named('Subscription')) {
-        $subscription->Delete;
-    }
-} # }}}
-
 my $good_time = 1290423660; # 6:01 EST on a monday
 my $bad_time  = 1290427260; # 7:01 EST on a monday
 
@@ -223,21 +212,9 @@ SKIP: {
 
 delete_dashboard($dashboard_id);
 
-warning_like {
-    RT::Dashboard::Mailer->MailDashboards(All => 1);
-} qr/Unable to load dashboard $dashboard_id of subscription $subscription_id for user root/;
-
- at mails = RT::Test->fetch_caught_mails;
-is(@mails, 1, "one mail for subscription failure");
-$mail = parse_mail($mails[0]);
-is($mail->head->get('Subject'), "[example.com] Missing dashboard!\n");
-is($mail->head->get('From'), "dashboard\@example.com\n");
-is($mail->head->get('X-RT-Dashboard-Id'), "$dashboard_id\n");
-is($mail->head->get('X-RT-Dashboard-Subscription-Id'), "$subscription_id\n");
-
 RT::Dashboard::Mailer->MailDashboards(All => 1);
 @mails = RT::Test->fetch_caught_mails;
-is(@mails, 0, "no mail because the subscription notice happens only once");
+is(@mails, 0, "no mail because the subscription is deleted");
 
 RT::Test->stop_server;
 RT::Test->clean_caught_mails;
@@ -277,7 +254,6 @@ RT->Config->Set('EmailDashboardRemove' => (qr/My dashboards/, "Testing!"));
 ($baseurl, $m) = RT::Test->started_ok;
 
 delete_dashboard($dashboard_id);
-delete_subscriptions();
 
 RT::Test->clean_caught_mails;
 
@@ -330,7 +306,6 @@ RT->Config->Set('EmailDashboardRemove' => (qr/My dashboards/, "Testing!"));
 ($baseurl, $m) = RT::Test->started_ok;
 
 delete_dashboard($dashboard_id);
-delete_subscriptions();
 
 RT::Test->clean_caught_mails;
 
@@ -373,7 +348,6 @@ RT->Config->Set('EmailDashboardRemove' => (qr/My dashboards/, "Testing!"));
 ($baseurl, $m) = RT::Test->started_ok;
 
 delete_dashboard($dashboard_id);
-delete_subscriptions();
 
 RT::Test->clean_caught_mails;
 

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


More information about the Rt-commit mailing list