[Bps-public-commit] rt-extension-notificationmatrix branch, master, updated. 3956a14f9e8070b98d275be98dfb2653b9769b8d
Chia-liang Kao
clkao at bestpractical.com
Thu Jul 15 12:50:31 EDT 2010
The branch, master has been updated
via 3956a14f9e8070b98d275be98dfb2653b9769b8d (commit)
from 333a74b37d6f979cd5656a40c934210b00e9656a (commit)
Summary of changes:
html/Admin/Queues/NotificationMatrix.html | 28 +++++++++++++++++++-----
lib/RT/Extension/NotificationMatrix/Rule.pm | 30 ++++++++++++++++++--------
2 files changed, 43 insertions(+), 15 deletions(-)
- Log -----------------------------------------------------------------
commit 3956a14f9e8070b98d275be98dfb2653b9769b8d
Author: Chia-liang Kao <clkao at clkao.org>
Date: Fri Jul 16 00:50:52 2010 +0800
support negation.
diff --git a/html/Admin/Queues/NotificationMatrix.html b/html/Admin/Queues/NotificationMatrix.html
index 77257b4..6842b34 100644
--- a/html/Admin/Queues/NotificationMatrix.html
+++ b/html/Admin/Queues/NotificationMatrix.html
@@ -52,28 +52,43 @@ Find User defined groups:
</form>
% }
+<p>
+Notifications for this queue will be sent to people in the groups or roles checked with the "inclusion" button, minus those found in the groups or roles checked with the "exclusion" button.
+</p>
+
<form method="post">
<input type="hidden" name="SetMatrix" value="1">
<table class="notification-matrix">
<tr class="group-type">
<th></th>
-<th colspan="<% scalar @groups %>"><&|/l&>Ticket Roles</&></th>
+<th colspan="<% 2 *scalar @groups %>"><&|/l&>Ticket Roles</&></th>
% if (@user_groups) {
-<th colspan="<% scalar @user_groups %>"><&|/l&>User Defined Groups</&></th>
+<th colspan="<% 2 * scalar @user_groups %>"><&|/l&>User Defined Groups</&></th>
% }
</tr>
<tr class="sep">
<th></th>
% for my $Group (@groups, @user_groups) {
- <th class="group-item"><% $Group->Domain eq 'UserDefined' ? $Group->Name : $Group->Type %></th>
+ <th class="group-item" colspan="2"><% $Group->Domain eq 'UserDefined' ? $Group->Name : $Group->Type %></th>
+% }
+</tr>
+<tr class="sep">
+<th></th>
+% for my $Group (@groups, @user_groups) {
+ <th class="group-item">Inc</th>
+ <th class="group-item">Exc</th>
% }
</tr>
% for my $action (@actions) {
<tr>
<th class="action"><% ("RT::Extension::NotificationMatrix::Rule::".$action)->Description %></th>
% for my $Group (@groups, @user_groups) {
-<td><input type="checkbox" name="NM-<% $action %>-<% $Group->Id %>" <% $matrix_hash->{$action}{$Group->Id} ? 'checked' : '' %> />
+<td>
+<input type="radio" name="NM-<% $action %>-<% $Group->Id %>" ondblclick="if(this.checked) this.checked=false" value="include" <% $matrix_hash->{$action}{$Group->Id} ? 'checked' : '' %> />
+</td>
+<td>
+<input type="radio" name="NM-<% $action %>-<% $Group->Id %>" ondblclick="if(this.checked) this.checked=false" value="exclude" <% $matrix_hash->{$action}{-$Group->Id} ? 'checked' : '' %> />
</td>
% }
</tr>
@@ -125,7 +140,8 @@ if ($ARGS{SelectUserGroup}) {
if ($ARGS{SetMatrix}) {
for my $action (@actions) {
# XXX: move this to some api and do permission check
- $matrix->{$action} = [ map { s/NM-\Q$action\E-// ? $_ : () } keys %ARGS ];
+ $matrix->{$action} = [ map { $ARGS{"NM-$action-$_"} eq 'include' ? $_ : -$_ }
+ map { s/NM-\Q$action\E-// ? $_ : () } keys %ARGS ]
}
$QueueObj->SetAttribute(Name => 'NotificationMatrix', Description => 'Notification Matrix Internal Data', Content => $matrix);
}
@@ -138,7 +154,7 @@ my $matrix_hash = { map { $_ => { map { $_ => 1 } @{$matrix->{$_}} } } keys %$ma
use List::MoreUtils qw(uniq);
-for (uniq map { @{$matrix->{$_}} } keys %$matrix) {
+for (uniq map { abs($_) } map { @{$matrix->{$_}} } keys %$matrix) {
unless ($group_hash->{$_}) {
my $group = RT::Group->new($session{'CurrentUser'});
$group->LoadUserDefinedGroup($_);
diff --git a/lib/RT/Extension/NotificationMatrix/Rule.pm b/lib/RT/Extension/NotificationMatrix/Rule.pm
index 2cdf5f6..367ccba 100644
--- a/lib/RT/Extension/NotificationMatrix/Rule.pm
+++ b/lib/RT/Extension/NotificationMatrix/Rule.pm
@@ -1,7 +1,7 @@
package RT::Extension::NotificationMatrix::Rule;
use strict;
use warnings;
-use List::MoreUtils qw(uniq);
+use List::MoreUtils qw(part);
use RT::Action::SendEmail;
use base 'RT::Rule';
@@ -12,15 +12,27 @@ sub GetRecipients {
my $t = $matrix->{$self->NM_Entry} or return;
$self->ConditionMatched or return;
+ my ($include, $exclude) = part { $_ > 0 ? 0 : 1 } @$t;
- 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;
+ my %address = map { $_ => 1 }
+ map { $self->_AddressesFromGroup($_) } @$include;
+
+ for (map { $self->_AddressesFromGroup(-$_) } @$exclude ) {
+ delete $address{$_};
+ }
+
+ return sort keys %address;
+
+}
+
+sub _AddressesFromGroup {
+ my ($self, $id) = @_;
+ my $g = RT::Group->new($self->CurrentUser);
+ $g->Load($id);
+ if ($g->Domain eq 'RT::Queue-Role') {
+ $g->LoadTicketRoleGroup( Ticket => $self->TicketObj->Id, Type => $g->Type);
+ }
+ $g->MemberEmailAddresses
}
sub ScripConditionMatched {
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list