[Bps-public-commit] rt-extension-notificationmatrix branch, master, updated. f15ba53761dc97d76126b2d8f44980940a624ddd
Chia-liang Kao
clkao at bestpractical.com
Tue Jul 27 02:18:50 EDT 2010
The branch, master has been updated
via f15ba53761dc97d76126b2d8f44980940a624ddd (commit)
via b2311db38c9fb7a01dc058db264100288669e2d6 (commit)
via 964ccf6b6f915d6c698ab80a4dfb8e552e63d5b5 (commit)
via 177cc7de942d1ebfa26299a46a4ea7dd90c36e75 (commit)
via 5d7d6c4287515c4977b96e744f306770a80a18d4 (commit)
from 689d8506167d1fb4491c744fc55e9c348f690e84 (commit)
Summary of changes:
html/test.html | 24 ------
lib/RT/Extension/NotificationMatrix/Rule.pm | 83 +++++++++++++++----
.../NotificationMatrix/Rule/TicketCreated.pm | 1 +
.../Rule/TicketUpdatedExternally.pm | 1 +
t/basic.t | 17 ++++-
5 files changed, 81 insertions(+), 45 deletions(-)
delete mode 100644 html/test.html
- Log -----------------------------------------------------------------
commit 5d7d6c4287515c4977b96e744f306770a80a18d4
Author: Chia-liang Kao <clkao at clkao.org>
Date: Tue Jul 20 21:22:22 2010 +0800
remove useless template.
diff --git a/html/test.html b/html/test.html
deleted file mode 100644
index c416592..0000000
--- a/html/test.html
+++ /dev/null
@@ -1,24 +0,0 @@
-<& /Admin/Elements/Header, Title => $title &>
-<& /Admin/Elements/QueueTabs, id => $QueueObj->id,
- QueueObj => $QueueObj,
- current_tab => 'Admin/Queues/Scrips.html?id='.$id,
- current_subtab => 'Admin/Queues/Scrips.html?id='.$id,
- subtabs => $subtabs,
- Title => $title &>
-
-<%init>
-
-my $QueueObj = RT::Queue->new($session{'CurrentUser'});
-$QueueObj->Load($id);
-
-my $title;
-
-if ($QueueObj->id) {
- $title = loc("Modify notification matrix for queue [_1]", $QueueObj->Name);
-} else {
- Abort(loc("Queue [_1] not found",$id));
-}
-</%init>
-<%args>
-$id => 1 #some identifier that a Queue could
-</%args>
commit 177cc7de942d1ebfa26299a46a4ea7dd90c36e75
Author: Chia-liang Kao <clkao at clkao.org>
Date: Tue Jul 27 11:40:40 2010 +0800
send to queue watchers as well as ticket watchers.
diff --git a/lib/RT/Extension/NotificationMatrix/Rule.pm b/lib/RT/Extension/NotificationMatrix/Rule.pm
index 367ccba..0d839d9 100644
--- a/lib/RT/Extension/NotificationMatrix/Rule.pm
+++ b/lib/RT/Extension/NotificationMatrix/Rule.pm
@@ -29,10 +29,12 @@ sub _AddressesFromGroup {
my ($self, $id) = @_;
my $g = RT::Group->new($self->CurrentUser);
$g->Load($id);
+ my @emails = $g->MemberEmailAddresses;
if ($g->Domain eq 'RT::Queue-Role') {
$g->LoadTicketRoleGroup( Ticket => $self->TicketObj->Id, Type => $g->Type);
+ push @emails, $g->MemberEmailAddresses;
}
- $g->MemberEmailAddresses
+ return @emails;
}
sub ScripConditionMatched {
commit 964ccf6b6f915d6c698ab80a4dfb8e552e63d5b5
Author: Chia-liang Kao <clkao at clkao.org>
Date: Tue Jul 27 13:59:55 2010 +0800
split external and internal sendemail actions.
diff --git a/lib/RT/Extension/NotificationMatrix/Rule.pm b/lib/RT/Extension/NotificationMatrix/Rule.pm
index 0d839d9..ab512b0 100644
--- a/lib/RT/Extension/NotificationMatrix/Rule.pm
+++ b/lib/RT/Extension/NotificationMatrix/Rule.pm
@@ -5,8 +5,13 @@ use List::MoreUtils qw(part);
use RT::Action::SendEmail;
use base 'RT::Rule';
+sub GetExternalRecipients {
+ my $self = shift;
+ return $self->GetRecipients(1);
+}
+
sub GetRecipients {
- my $self = shift;
+ my ($self, $external) = @_;
my $matrix = RT::Extension::NotificationMatrix->get_queue_matrix($self->TicketObj->QueueObj);
my $t = $matrix->{$self->NM_Entry} or return;
@@ -15,9 +20,9 @@ sub GetRecipients {
my ($include, $exclude) = part { $_ > 0 ? 0 : 1 } @$t;
my %address = map { $_ => 1 }
- map { $self->_AddressesFromGroup($_) } @$include;
+ map { $self->_AddressesFromGroup($_, $external) } @$include;
- for (map { $self->_AddressesFromGroup(-$_) } @$exclude ) {
+ for (map { $self->_AddressesFromGroup(-$_, $external) } @$exclude ) {
delete $address{$_};
}
@@ -25,13 +30,19 @@ sub GetRecipients {
}
+# external : requestor & cc
+
sub _AddressesFromGroup {
- my ($self, $id) = @_;
+ my ($self, $id, $external) = @_;
my $g = RT::Group->new($self->CurrentUser);
$g->Load($id);
+
+ my $is_external = $g->Domain eq 'RT::Queue-Role' && ($g->Type eq 'Requestor' || $g->Type eq 'Cc');
+ return if $external xor $is_external;
+
my @emails = $g->MemberEmailAddresses;
if ($g->Domain eq 'RT::Queue-Role') {
- $g->LoadTicketRoleGroup( Ticket => $self->TicketObj->Id, Type => $g->Type);
+ $g->LoadTicketRoleGroup( Ticket => $self->TicketObj->Id, Type => $g->Type );
push @emails, $g->MemberEmailAddresses;
}
return @emails;
@@ -58,14 +69,20 @@ sub ScripConditionMatched {
sub DefaultTemplate {}
+sub DefaultExternalTemplate {
+ $_[0]->DefaultTemplate;
+}
+
sub LoadTemplate {
- my $self = shift;
+ my ($self, $external) = @_;
my $template = RT::Template->new($self->CurrentUser);
my $name = ref($self);
$name =~ s/^RT::Extension::NotificationMatrix::Rule::// or die "unknown rule: $name";
-
- for my $tname ($self->TicketObj->QueueObj->Name.'-'.$name, $name, $self->DefaultTemplate, 'Transaction') {
+ my @templates = ($self->TicketObj->QueueObj->Name.'-'.$name, $name);
+ @templates = map { $_.'-External' } @templates if $external;
+ push @templates, $external ? $self->DefaultExternalTemplate : $self->DefaultTemplate;
+ for my $tname (@templates, 'Transaction') {
$template->Load($tname);
last if $template->Id;
}
@@ -84,10 +101,32 @@ sub Description {
return "Notification for $name";
}
-sub Prepare {
- my $self = shift;
+sub PrepareExternal {
+ my ($self) = @_;
+ my @recipients = $self->GetExternalRecipients or return;
+
+ my $template = $self->LoadTemplate(1);
+ # 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->{__ref} = $ref;
+ $email->Prepare;
+ return $email;
+}
- my @recipients = $self->GetRecipients or return 0;
+sub PrepareInternal {
+ my ($self) = @_;
+ my @recipients = $self->GetRecipients or return;
my $template = $self->LoadTemplate;
# RT::Action weakens the following, so we need to keep additional references
@@ -100,21 +139,27 @@ sub Prepare {
ScripActionObj => $ref->[1],
TemplateObj => $ref->[2],
TicketObj => $self->TicketObj,
- TransactionObj => $self->TransactionObj,
- );
+ TransactionObj => $self->TransactionObj );
+
$email->{To} = \@recipients;
+ $email->{__ref} = $ref;
$email->Prepare;
- $self->{__ref} = $ref;
- $self->{__email} = $email;
+ return $email;
+}
+
+sub Prepare {
+ my $self = shift;
+
+ $self->{__email} = [($self->PrepareInternal(), $self->PrepareExternal())];
$self->{hints} = { class => 'SendEmail',
- recipients => { To => \@recipients } };
+ recipients => { To => [ map { $_->{To} } @{$self->{__email}} ] } };
return 1;
}
sub Commit {
my $self = shift;
if ($self->{__email}) {
- $self->{__email}->Commit;
+ $_->Commit for @{$self->{__email}};
}
}
commit b2311db38c9fb7a01dc058db264100288669e2d6
Author: Chia-liang Kao <clkao at clkao.org>
Date: Tue Jul 27 14:19:09 2010 +0800
Provide default external templates for TicketUpdatedExternally and TicketCreated
diff --git a/lib/RT/Extension/NotificationMatrix/Rule/TicketCreated.pm b/lib/RT/Extension/NotificationMatrix/Rule/TicketCreated.pm
index 342c041..d14b596 100644
--- a/lib/RT/Extension/NotificationMatrix/Rule/TicketCreated.pm
+++ b/lib/RT/Extension/NotificationMatrix/Rule/TicketCreated.pm
@@ -6,6 +6,7 @@ use base 'RT::Extension::NotificationMatrix::Rule';
use constant NM_Entry => 'TicketCreated';
use constant Description => 'When ticket is created';
+use constant DefaultExternalTemplate => 'AutoReply';
sub ConditionMatched {
my $self = shift;
diff --git a/lib/RT/Extension/NotificationMatrix/Rule/TicketUpdatedExternally.pm b/lib/RT/Extension/NotificationMatrix/Rule/TicketUpdatedExternally.pm
index 33d7b51..a438150 100644
--- a/lib/RT/Extension/NotificationMatrix/Rule/TicketUpdatedExternally.pm
+++ b/lib/RT/Extension/NotificationMatrix/Rule/TicketUpdatedExternally.pm
@@ -5,6 +5,7 @@ use base 'RT::Extension::NotificationMatrix::Rule';
use constant NM_Entry => 'TicketUpdatedExternally';
use constant DefaultTemplate => 'Admin Correspondence';
+use constant DefaultExternalTemplate => 'Correspondence';
use constant Description => 'When ticket is updated externally';
sub ConditionMatched {
commit f15ba53761dc97d76126b2d8f44980940a624ddd
Author: Chia-liang Kao <clkao at clkao.org>
Date: Tue Jul 27 14:20:36 2010 +0800
test for external tempaltes.
diff --git a/t/basic.t b/t/basic.t
index e2bda44..575ac1f 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -10,7 +10,7 @@ BEGIN {
}
use RT;
-use RT::Test tests => 14;
+use RT::Test tests => 15;
use RT::Test::Email;
RT->Config->Set( LogToScreen => 'debug' );
RT->Config->Set('Plugins',qw(RT::Extension::NotificationMatrix));
@@ -105,8 +105,14 @@ 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 ],
- TicketTaken => [ $groups{group_b}->id ],
+my $requestors = RT::Group->new($RT::SystemUser);
+$requestors->LoadQueueRoleGroup(Queue => $q->Id, Type => 'Requestor');
+
+my $admincc = RT::Group->new($RT::SystemUser);
+$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 ],
};
@@ -128,8 +134,13 @@ mail_ok {
to => 'user_a at company.com, user_b at company.com',
subject => qr/a test/,
body => qr/Transaction: Ticket created by USER_B/,
+}, { from => qr'USER_B via RT',
+ to => 'user_b at company.com',
+ subject => qr/a test/,
+ body => qr/automatically generated in response/,
};
+
mail_ok {
my ($res, $msg) = $t->SetOwner($users{user_b});
ok($res, $msg);
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list