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

Chia-liang Kao clkao at bestpractical.com
Tue Aug 31 06:10:04 EDT 2010


The branch, master has been updated
       via  adb914a668edae29582194c8d1057bd52b56572b (commit)
       via  61d5985c1d79a8f8554817ed3ef60a74c91b9037 (commit)
       via  26e86143cd312f5e8d2f7b6ee09db784066843f8 (commit)
      from  a903c8dc41d402e949e594e4d5cff9c5c2b9ab4a (commit)

Summary of changes:
 lib/RT/Extension/NotificationMatrix/Rule.pm |   75 ++++++++++++++++++--------
 t/basic.t                                   |   50 ++++++++++++++++--
 2 files changed, 98 insertions(+), 27 deletions(-)

- Log -----------------------------------------------------------------
commit 26e86143cd312f5e8d2f7b6ee09db784066843f8
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Tue Aug 31 17:20:22 2010 +0800

    refactor for providing recipient classes

diff --git a/lib/RT/Extension/NotificationMatrix/Rule.pm b/lib/RT/Extension/NotificationMatrix/Rule.pm
index 2e42de0..95b35fb 100644
--- a/lib/RT/Extension/NotificationMatrix/Rule.pm
+++ b/lib/RT/Extension/NotificationMatrix/Rule.pm
@@ -16,18 +16,23 @@ sub GetRecipients {
 
     my $t = $matrix->{$self->NM_Entry} or return;
 
+    my $address;
+
     $self->ConditionMatched or return;
-    my ($include, $exclude) = part { $_ > 0 ? 0 : 1 } @$t;
 
-    my %address = map { $_ => 1 }
-        map { $self->_AddressesFromGroup($_, $external) } @$include;
+    my ($include, $exclude) = part { $_ > 0 ? 0 : 1 } @$t;
 
-    for (map { $self->_AddressesFromGroup(-$_, $external) } @$exclude ) {
-        delete $address{$_};
+    for (@$include) {
+        my @addresses = $self->_AddressesFromGroup($_, $external);
+        $address->{To}{$_} = 1 for @addresses;
     }
 
-    return sort keys %address;
+    for my $excluded (map { $self->_AddressesFromGroup(-$_, $external) } @$exclude ) {
+        delete $address->{$_}{$excluded} for qw(To Cc Bcc);
+    }
 
+    return { map { $_ => [sort keys %{$address->{$_}} ] }
+                 qw(To Cc Bcc) };
 }
 
 # external : requestor & cc
@@ -102,7 +107,7 @@ sub Description {
 
 sub PrepareExternal {
     my ($self) = @_;
-    my @recipients = $self->GetExternalRecipients or return;
+    my $recipients = $self->GetExternalRecipients or return;
 
     my $template = $self->LoadTemplate(1);
     # RT::Action weakens the following, so we need to keep additional references
@@ -117,7 +122,7 @@ sub PrepareExternal {
                                              TicketObj      => $self->TicketObj,
                                              TransactionObj => $self->TransactionObj,
                                            );
-    $email->{To} = \@recipients;
+    $email->{$_} = $recipients->{$_} for qw(To Cc Bcc);
     $email->{__ref} = $ref;
     $email->Prepare;
     return $email;
@@ -125,7 +130,7 @@ sub PrepareExternal {
 
 sub PrepareInternal {
     my ($self) = @_;
-    my @recipients = $self->GetRecipients or return;
+    my $recipients = $self->GetRecipients or return;
 
     my $template = $self->LoadTemplate;
     # RT::Action weakens the following, so we need to keep additional references
@@ -140,7 +145,7 @@ sub PrepareInternal {
                                             TicketObj      => $self->TicketObj,
                                             TransactionObj => $self->TransactionObj );
 
-    $email->{To} = \@recipients;
+    $email->{$_} = $recipients->{$_} for qw(To Cc Bcc);
     $email->{__ref} = $ref;
     $email->Prepare;
     return $email;
@@ -151,7 +156,10 @@ sub Prepare {
 
     $self->{__email} = [($self->PrepareInternal(), $self->PrepareExternal())];
     $self->{hints} = { class => 'SendEmail',
-                       recipients => { To => [ map { @{$_->{To}} } @{$self->{__email}} ] } };
+                       recipients => { To =>  [ map { @{$_->{To}} } @{$self->{__email}} ],
+                                       Cc =>  [ map { @{$_->{Cc}} } @{$self->{__email}} ],
+                                       Bcc => [ map { @{$_->{Bcc}} } @{$self->{__email}} ],
+                                   } };
     return 1;
 }
 

commit 61d5985c1d79a8f8554817ed3ef60a74c91b9037
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Tue Aug 31 17:51:06 2010 +0800

    distinguish recipient class from group types.

diff --git a/lib/RT/Extension/NotificationMatrix/Rule.pm b/lib/RT/Extension/NotificationMatrix/Rule.pm
index 95b35fb..d5cb920 100644
--- a/lib/RT/Extension/NotificationMatrix/Rule.pm
+++ b/lib/RT/Extension/NotificationMatrix/Rule.pm
@@ -22,9 +22,9 @@ sub GetRecipients {
 
     my ($include, $exclude) = part { $_ > 0 ? 0 : 1 } @$t;
 
-    for (@$include) {
-        my @addresses = $self->_AddressesFromGroup($_, $external);
-        $address->{To}{$_} = 1 for @addresses;
+    for my $g (@$include) {
+        my ($class, @addresses) = $self->_AddressesFromGroupWithClass($g, $external);
+        $address->{$class}{$_} = 1 for @addresses;
     }
 
     for my $excluded (map { $self->_AddressesFromGroup(-$_, $external) } @$exclude ) {
@@ -39,6 +39,12 @@ sub GetRecipients {
 
 sub _AddressesFromGroup {
     my ($self, $id, $external) = @_;
+    my ($class, @email) = $self->_AddressesFromGroupWithClass($id, $external);
+    return @email;
+}
+
+sub _AddressesFromGroupWithClass {
+    my ($self, $id, $external) = @_;
     my $g = RT::Group->new($self->CurrentUser);
     $g->Load($id);
 
@@ -46,11 +52,17 @@ sub _AddressesFromGroup {
     return if $external xor $is_external;
 
     my @emails = $g->MemberEmailAddresses;
+    my $class = 'Bcc';
+
     if ($g->Domain eq 'RT::Queue-Role') {
         $g->LoadTicketRoleGroup( Ticket => $self->TicketObj->Id, Type => $g->Type );
         push @emails, $g->MemberEmailAddresses;
+        $class = $g->Type eq 'Cc'      ? 'Cc'
+               : $g->Type eq 'AdminCc' ? 'Bcc'
+                                       : 'To';
     }
-    return @emails;
+
+    return ($class, @emails);
 }
 
 sub ScripConditionMatched {
@@ -114,18 +126,7 @@ sub PrepareExternal {
     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->{$_} = $recipients->{$_} for qw(To Cc Bcc);
-    $email->{__ref} = $ref;
-    $email->Prepare;
-    return $email;
+    return $self->_PrepareSendEmail($recipients, $ref);
 }
 
 sub PrepareInternal {
@@ -137,6 +138,13 @@ sub PrepareInternal {
     my $ref = [RT::Scrip->new($self->CurrentUser),
                { _Message_ID => 0},
                $template];
+
+    return $self->_PrepareSendEmail($recipients, $ref);
+}
+
+sub _PrepareSendEmail {
+    my ($self, $recipients, $ref) = @_;
+
     my $email = RT::Action::SendEmail->new( Argument       => undef,
                                             CurrentUser    => $self->CurrentUser,
                                             ScripObj       => $ref->[0],
diff --git a/t/basic.t b/t/basic.t
index 575ac1f..360a79c 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -131,7 +131,7 @@ mail_ok {
                );
     ok($tid);
 } { from => qr'USER_B via RT',
-    to => 'user_a at company.com, user_b at company.com',
+    bcc => 'user_a at company.com, user_b at company.com', # from ticket created: group_a
     subject => qr/a test/,
     body => qr/Transaction: Ticket created by USER_B/,
 }, { from => qr'USER_B via RT',
@@ -140,12 +140,11 @@ mail_ok {
     body => qr/automatically generated in response/,
 };
 
-
 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',
+    bcc => 'user_b at company.com, user_c at company.com', # from ticket taken: group_b
     subject => qr/a test/,
     body => qr/Given to USER_B/,
 };

commit adb914a668edae29582194c8d1057bd52b56572b
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Tue Aug 31 18:10:20 2010 +0800

    reimplement the notifyactor and to-line logic from Action::Notify

diff --git a/lib/RT/Extension/NotificationMatrix/Rule.pm b/lib/RT/Extension/NotificationMatrix/Rule.pm
index d5cb920..4d2865f 100644
--- a/lib/RT/Extension/NotificationMatrix/Rule.pm
+++ b/lib/RT/Extension/NotificationMatrix/Rule.pm
@@ -154,6 +154,19 @@ sub _PrepareSendEmail {
                                             TransactionObj => $self->TransactionObj );
 
     $email->{$_} = $recipients->{$_} for qw(To Cc Bcc);
+    if ( RT->Config->Get('UseFriendlyToLine') ) {
+        unless (@{$email->{To}}) {
+            @{ $email->{'PseudoTo'} } = sprintf RT->Config->Get('FriendlyToLineFormat'), 'notification', $self->TicketObj->Id;
+        }
+    }
+
+    if (!RT->Config->Get('NotifyActor')) {
+        my $creatorObj = $self->TransactionObj->CreatorObj;
+        my $creator = $creatorObj->EmailAddress() || '';
+        @{ $email->{$_} }  = grep ( lc $_ ne lc $creator, @{ $email->{$_} } )
+            for qw(To Cc Bcc);
+    }
+
     $email->{__ref} = $ref;
     $email->Prepare;
     return $email;
diff --git a/t/basic.t b/t/basic.t
index 360a79c..0725f02 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -10,10 +10,12 @@ BEGIN {
 }
 
 use RT;
-use RT::Test tests => 15;
+use RT::Test tests => 23;
 use RT::Test::Email;
 RT->Config->Set( LogToScreen => 'debug' );
 RT->Config->Set('Plugins',qw(RT::Extension::NotificationMatrix));
+RT->Config->Set('NotifyActor',1);
+RT->Config->Set('UseFriendlyToLine',0);
 
 use_ok('RT::Extension::NotificationMatrix');
 
@@ -114,6 +116,7 @@ $admincc->LoadQueueRoleGroup(Queue => $q->Id, Type => 'AdminCc');
 my $matrix = { TicketCreated => [ $owners->id, $groups{group_a}->id, $requestors->id ],
                TicketTaken   => [ $groups{group_b}->id, $admincc->id ],
                TicketUpdatedExternally => [ $owners->id ],
+               TicketCommented => [ $groups{group_b}->id ],
            };
 
 $q->SetAttribute(Name => 'NotificationMatrix',
@@ -174,6 +177,46 @@ mail_ok {
     body => qr/foobar/,
 };
 
+mail_ok {
+    my $cu = RT::CurrentUser->new;
+    $cu->Load( $users{user_b} );
+    $t->SetCurrentUser($cu);
+    my $t2 = RT::Ticket->new($cu);
+    $t2->Load($t->id);
+    my ($res, $msg) = $t2->Correspond(Content => "foobar");
+    ok($res, $msg);
+};
+
+mail_ok {
+    my $cu = RT::CurrentUser->new;
+    $cu->Load( $users{user_a} );
+    $t->SetCurrentUser($cu);
+    my $t2 = RT::Ticket->new($cu);
+    $t2->Load($t->id);
+    my ($res, $msg) = $t2->Comment(Content => "foobar");
+    ok($res, $msg);
+} { from => qr'USER_A via RT',
+    bcc => 'user_b at company.com, user_c at company.com',
+    subject => qr/a test/,
+    body => qr/foobar/,
+};
+
+RT->Config->Set('NotifyActor',0);
+
+mail_ok {
+    my $cu = RT::CurrentUser->new;
+    $cu->Load( $users{user_b} );
+    $t->SetCurrentUser($cu);
+    my $t2 = RT::Ticket->new($cu);
+    $t2->Load($t->id);
+    my ($res, $msg) = $t2->Comment(Content => "foobar");
+    ok($res, $msg);
+} { from => qr'USER_B via RT',
+    bcc => 'user_c at company.com',
+    subject => qr/a test/,
+    body => qr/foobar/,
+};
+
 
 #my ($baseurl, $m) = RT::Test->started_ok;
 

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



More information about the Bps-public-commit mailing list