[Bps-public-commit] rt-extension-notificationmatrix branch, master, updated. 8cdc9a4c0917689b6717b3956ba55abf9ab6bf96

Chia-liang Kao clkao at bestpractical.com
Mon Jun 21 11:38:21 EDT 2010


The branch, master has been updated
       via  8cdc9a4c0917689b6717b3956ba55abf9ab6bf96 (commit)
       via  be750caeb9028d401e856c692c5decd11b190ac7 (commit)
       via  891cd5b28fdfda7f32acdaf41c40a291cc4db15b (commit)
      from  034e405625f2ad28d500029086c8098379d33042 (commit)

Summary of changes:
 lib/RT/Extension/NotificationMatrix.pm             |    6 +-
 lib/RT/Extension/NotificationMatrix/Notify.pm      |   59 ---------------
 lib/RT/Extension/NotificationMatrix/Rule.pm        |   79 ++++++++++++++++++++
 .../NotificationMatrix/Rule/QueueChanged.pm        |   13 +++
 .../NotificationMatrix/Rule/TicketCommented.pm     |   13 +++
 .../NotificationMatrix/Rule/TicketCreated.pm       |   13 +++
 .../NotificationMatrix/Rule/TicketResolved.pm      |   13 +++
 .../NotificationMatrix/Rule/TicketTaken.pm         |   15 ++++
 t/basic.t                                          |   26 +++++--
 9 files changed, 171 insertions(+), 66 deletions(-)
 delete mode 100644 lib/RT/Extension/NotificationMatrix/Notify.pm
 create mode 100644 lib/RT/Extension/NotificationMatrix/Rule.pm
 create mode 100644 lib/RT/Extension/NotificationMatrix/Rule/QueueChanged.pm
 create mode 100644 lib/RT/Extension/NotificationMatrix/Rule/TicketCommented.pm
 create mode 100644 lib/RT/Extension/NotificationMatrix/Rule/TicketCreated.pm
 create mode 100644 lib/RT/Extension/NotificationMatrix/Rule/TicketResolved.pm
 create mode 100644 lib/RT/Extension/NotificationMatrix/Rule/TicketTaken.pm

- Log -----------------------------------------------------------------
commit 891cd5b28fdfda7f32acdaf41c40a291cc4db15b
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Mon Jun 21 22:29:48 2010 +0800

    make use of the on create condition.

diff --git a/lib/RT/Extension/NotificationMatrix/Notify.pm b/lib/RT/Extension/NotificationMatrix/Notify.pm
index 2cec51d..dffda9a 100644
--- a/lib/RT/Extension/NotificationMatrix/Notify.pm
+++ b/lib/RT/Extension/NotificationMatrix/Notify.pm
@@ -5,6 +5,25 @@ use List::MoreUtils qw(uniq);
 use RT::Action::SendEmail;
 use base 'RT::Rule';
 
+sub OnCreate {
+    my $self = shift;
+
+    my $ConditionObj = RT::ScripCondition->new( $self->CurrentUser );
+    $ConditionObj->Load( "On Create" );
+
+
+    my $txn_type = $self->TransactionObj->Type;
+    return unless( $ConditionObj->ApplicableTransTypes =~ /(?:^|,)(?:Any|\Q$txn_type\E)(?:,|$)/i );
+    # Load the scrip's Condition object
+    $ConditionObj->LoadCondition(
+        ScripObj       => $self,
+        TicketObj      => $self->TicketObj,
+        TransactionObj => $self->TransactionObj,
+    );
+
+    return $ConditionObj->IsApplicable();
+}
+
 sub Prepare {
     my $self = shift;
 
@@ -12,6 +31,7 @@ sub Prepare {
     my $matrix = RT::Extension::NotificationMatrix->get_queue_matrix($q);
 
     if (my $t = $matrix->{TicketCreated}) {
+        return unless $self->OnCreate;
         my @recipients = uniq map {
             my $g = RT::Group->new($self->CurrentUser);
             $g->Load($_);

commit be750caeb9028d401e856c692c5decd11b190ac7
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Mon Jun 21 22:47:03 2010 +0800

    provide generic rule hook.

diff --git a/lib/RT/Extension/NotificationMatrix.pm b/lib/RT/Extension/NotificationMatrix.pm
index 424b13a..dc30135 100644
--- a/lib/RT/Extension/NotificationMatrix.pm
+++ b/lib/RT/Extension/NotificationMatrix.pm
@@ -7,7 +7,7 @@ our $VERSION = '1.6';
 RT::Ruleset->Add(
     Name => 'NotificationMatrix',
     Rules => [
-        'RT::Extension::NotificationMatrix::Notify',
+        'RT::Extension::NotificationMatrix::Rule::TicketCreated',
     ]);
 
 sub get_queue_matrix {
diff --git a/lib/RT/Extension/NotificationMatrix/Notify.pm b/lib/RT/Extension/NotificationMatrix/Notify.pm
deleted file mode 100644
index dffda9a..0000000
--- a/lib/RT/Extension/NotificationMatrix/Notify.pm
+++ /dev/null
@@ -1,79 +0,0 @@
-package  RT::Extension::NotificationMatrix::Notify;
-use strict;
-use warnings;
-use List::MoreUtils qw(uniq);
-use RT::Action::SendEmail;
-use base 'RT::Rule';
-
-sub OnCreate {
-    my $self = shift;
-
-    my $ConditionObj = RT::ScripCondition->new( $self->CurrentUser );
-    $ConditionObj->Load( "On Create" );
-
-
-    my $txn_type = $self->TransactionObj->Type;
-    return unless( $ConditionObj->ApplicableTransTypes =~ /(?:^|,)(?:Any|\Q$txn_type\E)(?:,|$)/i );
-    # Load the scrip's Condition object
-    $ConditionObj->LoadCondition(
-        ScripObj       => $self,
-        TicketObj      => $self->TicketObj,
-        TransactionObj => $self->TransactionObj,
-    );
-
-    return $ConditionObj->IsApplicable();
-}
-
-sub Prepare {
-    my $self = shift;
-
-    my $q = $self->TicketObj->QueueObj;
-    my $matrix = RT::Extension::NotificationMatrix->get_queue_matrix($q);
-
-    if (my $t = $matrix->{TicketCreated}) {
-        return unless $self->OnCreate;
-        my @recipients = uniq map {
-            my $g = RT::Group->new($self->CurrentUser);
-            $g->Load($_);
-            if ($g->Domain eq 'RT::Queue-Role') {
-                $g->LoadTicketRoleGroup( Ticket => $self->TicketObj->Id, Type => $g->Type);
-            }
-            $g->MemberEmailAddresses
-        } @$t;
-
-        if (@recipients) {
-            my $template = RT::Template->new($self->CurrentUser);
-            $template->Load('Transaction') or die;
-            # RT::Action weakens the following, so we need to keep additional references
-            my $ref = [RT::Scrip->new($self->CurrentUser),
-                       { _Message_ID => 0},
-                       $template];
-            my $email = RT::Action::SendEmail->new ( Argument => undef,
-                                                     CurrentUser => $self->CurrentUser,
-                                                     ScripObj => $ref->[0],
-                                                     ScripActionObj => $ref->[1],
-                                                     TemplateObj => $ref->[2],
-                                                     TicketObj => $self->TicketObj,
-                                                     TransactionObj => $self->TransactionObj,
-                                                 );
-            $email->{To} = \@recipients;
-            $email->Prepare;
-            $self->{__ref} = $ref;
-            $self->{__email} = $email;
-            return 1;
-        }
-
-    }
-
-    return 0;
-}
-
-sub Commit {
-    my $self = shift;
-    if ($self->{__email}) {
-        $self->{__email}->Commit;
-    }
-
-}
-
-1;
diff --git a/lib/RT/Extension/NotificationMatrix/Rule.pm b/lib/RT/Extension/NotificationMatrix/Rule.pm
new file mode 100644
index 0000000..ce271c5
--- /dev/null
+++ b/lib/RT/Extension/NotificationMatrix/Rule.pm
@@ -0,0 +1,79 @@
+package  RT::Extension::NotificationMatrix::Rule;
+use strict;
+use warnings;
+use List::MoreUtils qw(uniq);
+use RT::Action::SendEmail;
+use base 'RT::Rule';
+
+sub GetRecipients {
+    my $self   = shift;
+    my $matrix = RT::Extension::NotificationMatrix->get_queue_matrix($self->TicketObj->QueueObj);
+
+    my $t = $matrix->{$self->NM_Entry} or return;
+
+    $self->ConditionMatched or return;
+
+    return uniq map {
+        my $g = RT::Group->new($self->CurrentUser);
+        $g->Load($_);
+        if ($g->Domain eq 'RT::Queue-Role') {
+            $g->LoadTicketRoleGroup( Ticket => $self->TicketObj->Id, Type => $g->Type);
+        }
+        $g->MemberEmailAddresses
+    } @$t;
+}
+
+sub ScripConditionMatched {
+    my $self = shift;
+    my $name = shift;
+
+    my $ConditionObj = RT::ScripCondition->new( $self->CurrentUser );
+    $ConditionObj->Load( $name ) or die;
+
+    my $txn_type = $self->TransactionObj->Type;
+    return unless( $ConditionObj->ApplicableTransTypes =~ /(?:^|,)(?:Any|\Q$txn_type\E)(?:,|$)/i );
+    # Load the scrip's Condition object
+    $ConditionObj->LoadCondition(
+        ScripObj       => $self,
+        TicketObj      => $self->TicketObj,
+        TransactionObj => $self->TransactionObj,
+    );
+
+    return $ConditionObj->IsApplicable();
+}
+
+sub Prepare {
+    my $self = shift;
+
+    my @recipients = $self->GetRecipients or return 0;
+
+    my $template = RT::Template->new($self->CurrentUser);
+    $template->Load('Transaction') or die;
+    # RT::Action weakens the following, so we need to keep additional references
+    my $ref = [RT::Scrip->new($self->CurrentUser),
+               { _Message_ID => 0},
+               $template];
+    my $email = RT::Action::SendEmail->new( Argument       => undef,
+                                            CurrentUser    => $self->CurrentUser,
+                                            ScripObj       => $ref->[0],
+                                            ScripActionObj => $ref->[1],
+                                            TemplateObj    => $ref->[2],
+                                            TicketObj      => $self->TicketObj,
+                                            TransactionObj => $self->TransactionObj,
+                                        );
+    $email->{To} = \@recipients;
+    $email->Prepare;
+    $self->{__ref} = $ref;
+    $self->{__email} = $email;
+    return 1;
+}
+
+sub Commit {
+    my $self = shift;
+    if ($self->{__email}) {
+        $self->{__email}->Commit;
+    }
+
+}
+
+1;
diff --git a/lib/RT/Extension/NotificationMatrix/Rule/TicketCreated.pm b/lib/RT/Extension/NotificationMatrix/Rule/TicketCreated.pm
new file mode 100644
index 0000000..9612b9f
--- /dev/null
+++ b/lib/RT/Extension/NotificationMatrix/Rule/TicketCreated.pm
@@ -0,0 +1,13 @@
+package RT::Extension::NotificationMatrix::Rule::TicketCreated;
+use strict;
+use warnings;
+use base 'RT::Extension::NotificationMatrix::Rule';
+
+use constant NM_Entry => 'TicketCreated';
+
+sub ConditionMatched {
+    my $self = shift;
+    $self->ScripConditionMatched("On Create");
+}
+
+1;

commit 8cdc9a4c0917689b6717b3956ba55abf9ab6bf96
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Mon Jun 21 23:38:57 2010 +0800

    A few more conditions and tests.

diff --git a/lib/RT/Extension/NotificationMatrix.pm b/lib/RT/Extension/NotificationMatrix.pm
index dc30135..25ed776 100644
--- a/lib/RT/Extension/NotificationMatrix.pm
+++ b/lib/RT/Extension/NotificationMatrix.pm
@@ -8,6 +8,10 @@ RT::Ruleset->Add(
     Name => 'NotificationMatrix',
     Rules => [
         'RT::Extension::NotificationMatrix::Rule::TicketCreated',
+        'RT::Extension::NotificationMatrix::Rule::TicketCommented',
+        'RT::Extension::NotificationMatrix::Rule::TicketTaken',
+        'RT::Extension::NotificationMatrix::Rule::TicketResolved',
+        'RT::Extension::NotificationMatrix::Rule::QueueChanged',
     ]);
 
 sub get_queue_matrix {
diff --git a/lib/RT/Extension/NotificationMatrix/Rule/QueueChanged.pm b/lib/RT/Extension/NotificationMatrix/Rule/QueueChanged.pm
new file mode 100644
index 0000000..af843bb
--- /dev/null
+++ b/lib/RT/Extension/NotificationMatrix/Rule/QueueChanged.pm
@@ -0,0 +1,13 @@
+package RT::Extension::NotificationMatrix::Rule::QueueChanged;
+use strict;
+use warnings;
+use base 'RT::Extension::NotificationMatrix::Rule';
+
+use constant NM_Entry => 'QueueChanged';
+
+sub ConditionMatched {
+    my $self = shift;
+    $self->ScripConditionMatched("On Queue Change");
+}
+
+1;
diff --git a/lib/RT/Extension/NotificationMatrix/Rule/TicketCommented.pm b/lib/RT/Extension/NotificationMatrix/Rule/TicketCommented.pm
new file mode 100644
index 0000000..1ea2d52
--- /dev/null
+++ b/lib/RT/Extension/NotificationMatrix/Rule/TicketCommented.pm
@@ -0,0 +1,13 @@
+package RT::Extension::NotificationMatrix::Rule::TicketCommented;
+use strict;
+use warnings;
+use base 'RT::Extension::NotificationMatrix::Rule';
+
+use constant NM_Entry => 'TicketCommented';
+
+sub ConditionMatched {
+    my $self = shift;
+    $self->ScripConditionMatched("On Commit");
+}
+
+1;
diff --git a/lib/RT/Extension/NotificationMatrix/Rule/TicketResolved.pm b/lib/RT/Extension/NotificationMatrix/Rule/TicketResolved.pm
new file mode 100644
index 0000000..594cbd1
--- /dev/null
+++ b/lib/RT/Extension/NotificationMatrix/Rule/TicketResolved.pm
@@ -0,0 +1,13 @@
+package RT::Extension::NotificationMatrix::Rule::TicketResolved;
+use strict;
+use warnings;
+use base 'RT::Extension::NotificationMatrix::Rule';
+
+use constant NM_Entry => 'TicketResolved';
+
+sub ConditionMatched {
+    my $self = shift;
+    $self->ScripConditionMatched("On Resolve");
+}
+
+1;
diff --git a/lib/RT/Extension/NotificationMatrix/Rule/TicketTaken.pm b/lib/RT/Extension/NotificationMatrix/Rule/TicketTaken.pm
new file mode 100644
index 0000000..5abde86
--- /dev/null
+++ b/lib/RT/Extension/NotificationMatrix/Rule/TicketTaken.pm
@@ -0,0 +1,15 @@
+package RT::Extension::NotificationMatrix::Rule::TicketTaken;
+use strict;
+use warnings;
+use base 'RT::Extension::NotificationMatrix::Rule';
+
+use constant NM_Entry => 'TicketTaken';
+
+sub ConditionMatched {
+    my $self = shift;
+    my $txn = $self->TransactionObj;
+
+    return ($txn->Field eq 'Owner' && $txn->OldValue == $RT::Nobody->Id)
+}
+
+1;
diff --git a/t/basic.t b/t/basic.t
index f645e50..88e1d7e 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -10,7 +10,7 @@ BEGIN {
 }
 
 use RT;
-use RT::Test tests => 6;
+use RT::Test tests => 9;
 use RT::Test::Email;
 RT->Config->Set( LogToScreen => 'debug' );
 RT->Config->Set('Plugins',qw(RT::Extension::NotificationMatrix));
@@ -62,6 +62,7 @@ $group_obj = RT::Group->new($RT::SystemUser);
     for qw(user_b user_c);
 $groups{group_b} = $group_obj;
 
+$group_obj = RT::Group->new($RT::SystemUser);
 $group_obj->LoadSystemInternalGroup('Privileged');
 $group_obj->PrincipalObj->GrantRight(Object => $q, Right => $_)
     for (qw(OwnTicket ModifyTicket ShowTicket showticketcomments));
@@ -81,7 +82,7 @@ while (my $sc = $scrips->Next) {
 
 my ($tid, $ttrans, $tmsg);
 my $cu = RT::CurrentUser->new;
-$cu->Load( $users{user_a} );
+$cu->Load( $users{user_b} );
 
 my $t = RT::Ticket->new($cu);
 
@@ -103,7 +104,9 @@ my @groups = @{ $Groups->ItemsArrayRef };
 my $owners = RT::Group->new($RT::SystemUser);
 $owners->LoadQueueRoleGroup(Queue => $q->Id, Type => 'Owner');
 
-my $matrix = { TicketCreated => [ $owners->id, $groups{group_a}->id ] };
+my $matrix = { TicketCreated => [ $owners->id, $groups{group_a}->id ],
+               TicketTaken   => [ $groups{group_b}->id ],
+           };
 
 $q->SetAttribute(Name => 'NotificationMatrix',
                  Description => 'Notification Matrix Internal Data',
@@ -114,17 +117,28 @@ $q->SetAttribute(Name => 'NotificationMatrix',
 mail_ok {
     ($tid, $ttrans, $tmsg) =
         $t->Create(Subject => "a test",
-                   Owner => "user_a", Requestor => 'user_b',
+#                   Owner => "user_a", 
+                   Requestor => 'user_b',
                    Queue => $q->Id,
                    AdminCc => 'user_c',
                );
     ok($tid);
-} { from => qr'USER_A via RT',
+} { from => qr'USER_B via RT',
     to => 'user_a at company.com, user_b at company.com',
     subject => qr/a test/,
-    body => qr/Transaction: Ticket created by USER_A/,
+    body => qr/Transaction: Ticket created by USER_B/,
 };
 
+mail_ok {
+    my ($res, $msg) = $t->SetOwner($users{user_b});
+    ok($res, $msg);
+} { from => qr'USER_B via RT',
+    to => 'user_b at company.com, user_c at company.com',
+    subject => qr/a test/,
+    body => qr/Given to USER_B/,
+};
+
+
 #my ($baseurl, $m) = RT::Test->started_ok;
 
 #diag "$baseurl/?user=root&pass=password"; sleep 1 while 1;

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



More information about the Bps-public-commit mailing list