[Bps-public-commit] rt-extension-automaticassignment branch, master, updated. 946f76831bcf67956687f3a24e07e5974c020e11
Shawn Moore
shawn at bestpractical.com
Thu Jul 21 10:32:57 EDT 2016
The branch, master has been updated
via 946f76831bcf67956687f3a24e07e5974c020e11 (commit)
via c86084ce68409286ec1969e792dffbdec87b5940 (commit)
via 86c64c56026eacfa5d8f481f743616ca96e561d2 (commit)
via 3de952b43834b14db924add8eeec7e3f515d8934 (commit)
via 23db360551b1c6df4b242c6b47f782ed204c332c (commit)
via 187f405b2bc9fdf686ea75ca2474ac1db25574d9 (commit)
via 7828bd7c188b414e520bf407ab4649d11bb57b60 (commit)
via 1b11bdae03e52cbd4937379e2980435565e2d098 (commit)
via 9275a32d37e4e20605824c1e5837c8473a4d7cc1 (commit)
via 24b7ccf3aeac12098ff6899e981333b79516b73d (commit)
from f5c8fba19c304b2320c112c6c3ce7eee9d6e024e (commit)
Summary of changes:
lib/RT/Action/AutomaticAssignment.pm | 2 +
lib/RT/Action/AutomaticReassignment.pm | 2 +
lib/RT/Extension/AutomaticAssignment.pm | 121 ++++++++++++++++-----
lib/RT/Extension/AutomaticAssignment/Chooser.pm | 2 +
.../AutomaticAssignment/Chooser/Random.pm | 6 +-
.../AutomaticAssignment/Chooser/RoundRobin.pm | 31 ++++++
.../Chooser/{Ownership.pm => TicketStatus.pm} | 6 +-
.../AutomaticAssignment/Chooser/TimeLeft.pm | 32 ++++++
lib/RT/Extension/AutomaticAssignment/Filter.pm | 13 +++
.../AutomaticAssignment/Filter/MemberOfGroup.pm | 35 ++++++
.../AutomaticAssignment/Filter/MemberOfRole.pm | 44 ++++++++
11 files changed, 264 insertions(+), 30 deletions(-)
create mode 100644 lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm
rename lib/RT/Extension/AutomaticAssignment/Chooser/{Ownership.pm => TicketStatus.pm} (95%)
create mode 100644 lib/RT/Extension/AutomaticAssignment/Chooser/TimeLeft.pm
create mode 100644 lib/RT/Extension/AutomaticAssignment/Filter.pm
create mode 100644 lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm
create mode 100644 lib/RT/Extension/AutomaticAssignment/Filter/MemberOfRole.pm
- Log -----------------------------------------------------------------
commit 24b7ccf3aeac12098ff6899e981333b79516b73d
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Jul 21 13:18:42 2016 +0000
Rename Ownership to TicketStatus
diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index 7e9e7e0..7a0ded6 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -102,9 +102,9 @@ will happen even if the ticket has an owner already.
Set(%AutomaticAssignment_Choosers, (
Default => 'Random',
QueueDefaults => {
- General => 'Ownership',
+ General => 'TicketStatus',
Review => {
- class => 'Ownership',
+ class => 'TicketStatus',
ties => [ ['new', 'open'], 'stalled' ],
},
},
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/Ownership.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm
similarity index 96%
rename from lib/RT/Extension/AutomaticAssignment/Chooser/Ownership.pm
rename to lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm
index 09b3bb9..1960b67 100644
--- a/lib/RT/Extension/AutomaticAssignment/Chooser/Ownership.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm
@@ -1,4 +1,4 @@
-package RT::Extension::AutomaticAssignment::Chooser::Ownership;
+package RT::Extension::AutomaticAssignment::Chooser::TicketStatus;
use strict;
use warnings;
use base 'RT::Extension::AutomaticAssignment::Chooser';
@@ -9,7 +9,7 @@ sub ChooseOwnerForTicket {
my @users = @{ shift(@_) };
my $config = shift;
- # for Ownership we only consider tickets in the same queue
+ # for TicketStatus we only consider tickets in the same queue
my $tickets = RT::Tickets->new($ticket->CurrentUser);
$tickets->LimitQueue(VALUE => $ticket->Queue);
commit 9275a32d37e4e20605824c1e5837c8473a4d7cc1
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Jul 21 13:28:44 2016 +0000
TimeLeft chooser
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/TimeLeft.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/TimeLeft.pm
new file mode 100644
index 0000000..b26d8dd
--- /dev/null
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/TimeLeft.pm
@@ -0,0 +1,32 @@
+package RT::Extension::AutomaticAssignment::Chooser::TimeLeft;
+use strict;
+use warnings;
+use base 'RT::Extension::AutomaticAssignment::Chooser';
+use List::Util 'reduce';
+
+sub ChooseOwnerForTicket {
+ my $class = shift;
+ my $ticket = shift;
+ my $users = shift;
+ my $config = shift;
+
+ # for TimeLeft we only consider tickets in the same queue
+ my $tickets = RT::Tickets->new($ticket->CurrentUser);
+ $tickets->LimitQueue(VALUE => $ticket->Queue);
+ $tickets->LimitToActiveStatus;
+
+ my %timeleft_by_owner;
+ while (my $ticket = $tickets->Next) {
+ next if $ticket->Owner = RT->Nobody->id;
+ my $time_left = $ticket->TimeLeft || ($ticket->TimeEstimated - $ticket->TimeWorked);
+ next if $time_left < 0;
+
+ $timeleft_by_owner{ $ticket->Owner } += $time_left;
+ }
+
+ return reduce { $timeleft_by_owner{$a->id} < $timeleft_by_owner{$b->id} ? $a : $b } @$users;
+}
+
+1;
+
+
commit 1b11bdae03e52cbd4937379e2980435565e2d098
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Jul 21 13:35:36 2016 +0000
Round Robin chooser
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm
new file mode 100644
index 0000000..adbda2f
--- /dev/null
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm
@@ -0,0 +1,31 @@
+package RT::Extension::AutomaticAssignment::Chooser::RoundRobin;
+use strict;
+use warnings;
+use base 'RT::Extension::AutomaticAssignment::Chooser';
+use List::Util 'reduce';
+
+sub ChooseOwnerForTicket {
+ my $class = shift;
+ my $ticket = shift;
+ my $users = shift;
+ my $config = shift;
+
+ my $queue = $ticket->Queue;
+ my $attr = 'AutomaticAssignment-RoundRobin-Queue' . $queue;
+
+ # find the user whose last round-robin automatic assignment in this queue
+ # was the longest time ago
+ my $owner = reduce {
+ ($a->FirstAttribute($attr)||0) < ($b->FirstAttribute($attr)||0) ? $a : $b
+ } @$users;
+
+ if ($owner) {
+ $owner->SetAttribute(Name => $attr, Content => time);
+ }
+
+ return $owner;
+}
+
+1;
+
+
commit 7828bd7c188b414e520bf407ab4649d11bb57b60
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Jul 21 13:36:23 2016 +0000
Use strict and warnings throughout
diff --git a/lib/RT/Action/AutomaticAssignment.pm b/lib/RT/Action/AutomaticAssignment.pm
index 1456510..0b3ad94 100644
--- a/lib/RT/Action/AutomaticAssignment.pm
+++ b/lib/RT/Action/AutomaticAssignment.pm
@@ -1,4 +1,6 @@
package RT::Action::AutomaticAssignment;
+use strict;
+use warnings;
use base 'RT::Action';
# only tickets that are unassigned will be automatically assigned.
diff --git a/lib/RT/Action/AutomaticReassignment.pm b/lib/RT/Action/AutomaticReassignment.pm
index ce5904c..0431367 100644
--- a/lib/RT/Action/AutomaticReassignment.pm
+++ b/lib/RT/Action/AutomaticReassignment.pm
@@ -1,4 +1,6 @@
package RT::Action::AutomaticReassignment;
+use strict;
+use warnings;
use base 'RT::Action::AutomaticAssignment';
# any owner is fine
diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index 7a0ded6..145ab27 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -1,6 +1,6 @@
+package RT::Extension::AutomaticAssignment;
use strict;
use warnings;
-package RT::Extension::AutomaticAssignment;
our $VERSION = '0.01';
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser.pm b/lib/RT/Extension/AutomaticAssignment/Chooser.pm
index 39735dd..e9ad025 100644
--- a/lib/RT/Extension/AutomaticAssignment/Chooser.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser.pm
@@ -1,4 +1,6 @@
package RT::Extension::AutomaticAssignment::Chooser;
+use strict;
+use warnings;
use base 'RT::Base';
sub ChooseOwnerForTicket {
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/Random.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/Random.pm
index bdcf518..8b39027 100644
--- a/lib/RT/Extension/AutomaticAssignment/Chooser/Random.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/Random.pm
@@ -1,4 +1,6 @@
package RT::Extension::AutomaticAssignment::Chooser::Random;
+use strict;
+use warnings;
use base 'RT::Extension::AutomaticAssignment::Chooser';
sub ChooseOwnerForTicket {
commit 187f405b2bc9fdf686ea75ca2474ac1db25574d9
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Jul 21 14:01:25 2016 +0000
Users now passed to filter as a collection not arrayref
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/Random.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/Random.pm
index 8b39027..8e2ca4b 100644
--- a/lib/RT/Extension/AutomaticAssignment/Chooser/Random.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/Random.pm
@@ -6,10 +6,10 @@ use base 'RT::Extension::AutomaticAssignment::Chooser';
sub ChooseOwnerForTicket {
my $class = shift;
my $ticket = shift;
- my $users = shift;
+ my @users = @{ shift->ItemsArrayRef };
my $config = shift;
- return $users->[rand @$users];
+ return $users[rand @users];
}
1;
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm
index adbda2f..33cae0d 100644
--- a/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm
@@ -7,7 +7,7 @@ use List::Util 'reduce';
sub ChooseOwnerForTicket {
my $class = shift;
my $ticket = shift;
- my $users = shift;
+ my @users = @{ shift->ItemsArrayRef };
my $config = shift;
my $queue = $ticket->Queue;
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm
index 1960b67..fbdc109 100644
--- a/lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/TicketStatus.pm
@@ -6,7 +6,7 @@ use base 'RT::Extension::AutomaticAssignment::Chooser';
sub ChooseOwnerForTicket {
my $class = shift;
my $ticket = shift;
- my @users = @{ shift(@_) };
+ my @users = @{ shift->ItemsArrayRef };
my $config = shift;
# for TicketStatus we only consider tickets in the same queue
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/TimeLeft.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/TimeLeft.pm
index b26d8dd..5db7ae4 100644
--- a/lib/RT/Extension/AutomaticAssignment/Chooser/TimeLeft.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/TimeLeft.pm
@@ -7,7 +7,7 @@ use List::Util 'reduce';
sub ChooseOwnerForTicket {
my $class = shift;
my $ticket = shift;
- my $users = shift;
+ my @users = @{ shift->ItemsArrayRef };
my $config = shift;
# for TimeLeft we only consider tickets in the same queue
@@ -24,7 +24,7 @@ sub ChooseOwnerForTicket {
$timeleft_by_owner{ $ticket->Owner } += $time_left;
}
- return reduce { $timeleft_by_owner{$a->id} < $timeleft_by_owner{$b->id} ? $a : $b } @$users;
+ return reduce { $timeleft_by_owner{$a->id} < $timeleft_by_owner{$b->id} ? $a : $b } @users;
}
1;
commit 23db360551b1c6df4b242c6b47f782ed204c332c
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Jul 21 14:01:42 2016 +0000
Refactor config loading and some method names
diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index 145ab27..b242576 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -4,56 +4,119 @@ use warnings;
our $VERSION = '0.01';
-sub AvailableOwnersForTicket {
- my $class = shift;
+sub _LoadedClass {
+ my $self = shift;
+ my $namespace = shift;
+ my $name = shift;
+
+ my $class = $name =~ /::/ ? $name : "RT::Extension::AutomaticAssignment::${namespace}::$name";
+ $class->require or die $UNIVERSAL::require::ERROR;
+ return $class;
+}
+
+sub _UnfilteredOwnersForTicket {
+ my $self = shift;
my $ticket = shift;
my $users = RT::Users->new(RT->SystemUser);
$users->LimitToPrivileged;
- return $users->ItemsArrayRef;
+ $users->WhoHaveRight(
+ Right => 'OwnTicket',
+ Object => $ticket,
+ IncludeSystemRights => 1,
+ IncludeSuperusers => 1,
+ );
+
+ return $users;
+}
+
+sub _EligibleOwnersForTicket {
+ my $self = shift;
+ my $ticket = shift;
+ my $config = shift;
+
+ my $users = $self->_UnfilteredOwnersForTicket($ticket);
+
+ for my $filter (@{ $config->{filters} }) {
+ my $class = $filter->{class};
+ $class->FilterOwnersForTicket($ticket, $users, $filter);
+ }
+
+ return $users;
}
-sub ChooseOwnerForTicket {
- my $class = shift;
+sub _ChooseOwnerForTicket {
+ my $self = shift;
my $ticket = shift;
my $users = shift;
+ my $config = shift;
+
+ my $class = $config->{chooser};
+ return $class->ChooseOwnerForTicket($ticket, $users, $config->{chooser});
+}
+
+sub _ConfigForTicket {
+ my $self = shift;
+ my $ticket = shift;
my $queue = $ticket->QueueObj->Name;
- my $choosers = RT->Config->Get('AutomaticAssignment_Choosers');
- if (!$choosers) {
- RT->Logger->error("No AutomaticAssignment_Choosers defined; automatic assignment cannot occur.");
+ my $config = RT->Config->Get('AutomaticAssignment');
+ if (!$config) {
+ RT->Logger->error("No AutomaticAssignment config defined; automatic assignment cannot occur.");
return;
}
- my $config = $choosers->{QueueDefault}{ $queue } || $choosers->{Default};
- my $chooser_name;
+ # merge the queue-specific config into the default config
+ my %merged_config = %{ $config->{Default} || {} };
+ $merged_config{ $_ } = $config->{QueueDefault}{ $queue }->{ $_ }
+ for keys %{ $config->{QueueDefault}{ $queue } || {} }
- if (!$config) {
- RT->Logger->error("No AutomaticAssignment_Choosers Default or QueueDefault for queue '$queue' defined; automatic assignment cannot occur.");
+ # filters not required, since the default list is "users who can own
+ # tickets in this queue"
+ $merged_config{filters} ||= [];
+
+ # chooser is required
+ if (!$merged_config{chooser}) {
+ RT->Logger->error("No AutomaticAssignment chooser defined for queue '$quuee'; automatic assignment cannot occur.");
return;
}
- if (ref($config)) {
- $chooser_name = $config->{class};
+ # load each filter class
+ for (@{ $merged_config{filters} }) {
+ if (!ref($_)) {
+ $_ = {
+ class => $self->_LoadedClass('Filter', $_),
+ };
+ }
+ else {
+ $_->{class} = $self->_LoadedClass('Filter', $_->{class});
+ }
+ }
+
+ # load chooser class
+ if (!ref($merged_config{chooser})) {
+ $merged_config{chooser} = {
+ class => $self->_LoadedClass('Chooser', $merged_config{chooser}),
+ };
}
else {
- $chooser_name = $config;
- $config = {};
+ $merged_config{chooser}{class} = $self->_LoadedClass('Chooser', $merged_config{chooser}{class});
}
- my $chooser_class = $chooser_name =~ /::/ ? $chooser_name : "RT::Extension::AutomaticAssignment::Chooser::$chooser_name";
- $chooser_class->require or die $UNIVERSAL::require::ERROR;
- return $chooser_class->ChooseOwnerForTicket($ticket, $users, $config);
+ return \%merged_config;
}
sub OwnerForTicket {
- my $class = shift;
+ my $self = shift;
my $ticket = shift;
- my $users = $class->AvailableOwnersForTicket($ticket);
+ my $config = $self->_ConfigForTicket($ticket);
+ return if !$config;
+
+ my $users = $self->_EligibleOwnersForTicket($ticket, $config);
return if !$users;
- my $user = $class->ChooseOwnerForTicket($ticket, $users);
+ my $user = $self->_ChooseOwnerForTicket($ticket, $users, $config);
return $user;
}
commit 3de952b43834b14db924add8eeec7e3f515d8934
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Jul 21 14:05:09 2016 +0000
Support coderef filters
diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index b242576..1eda3aa 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -38,8 +38,13 @@ sub _EligibleOwnersForTicket {
my $users = $self->_UnfilteredOwnersForTicket($ticket);
for my $filter (@{ $config->{filters} }) {
- my $class = $filter->{class};
- $class->FilterOwnersForTicket($ticket, $users, $filter);
+ if (ref($filter) eq 'CODE') {
+ $filter->($users, $ticket);
+ }
+ else {
+ my $class = $filter->{class};
+ $class->FilterOwnersForTicket($ticket, $users, $filter);
+ }
}
return $users;
@@ -88,6 +93,9 @@ sub _ConfigForTicket {
class => $self->_LoadedClass('Filter', $_),
};
}
+ elsif (ref($_) eq 'CODE') {
+ # nothing to do
+ }
else {
$_->{class} = $self->_LoadedClass('Filter', $_->{class});
}
commit 86c64c56026eacfa5d8f481f743616ca96e561d2
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Jul 21 14:29:33 2016 +0000
MemberOfGroup filter
diff --git a/lib/RT/Extension/AutomaticAssignment/Filter.pm b/lib/RT/Extension/AutomaticAssignment/Filter.pm
new file mode 100644
index 0000000..b08f68f
--- /dev/null
+++ b/lib/RT/Extension/AutomaticAssignment/Filter.pm
@@ -0,0 +1,13 @@
+package RT::Extension::AutomaticAssignment::Filter;
+use strict;
+use warnings;
+use base 'RT::Base';
+
+sub FilterOwnersForTicket {
+ my $self = shift;
+ die "Subclass " . ref($self) . " of " . __PACKAGE__ . " does not implement required method FilterOwnersForTicket";
+}
+
+1;
+
+
diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm b/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm
new file mode 100644
index 0000000..53954aa
--- /dev/null
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm
@@ -0,0 +1,26 @@
+package RT::Extension::AutomaticAssignment::Filter::MemberOfGroup;
+use strict;
+use warnings;
+use base 'RT::Extension::AutomaticAssignment::Filter';
+
+sub FilterOwnersForTicket {
+ my $class = shift;
+ my $ticket = shift;
+ my $users = shift;
+ my $config = shift;
+
+ my $group_name = $config->{name}
+ or die "Unable to filter MemberOfGroup; no name provided.";
+
+ my $group = RT::Group->new($ticket->CurrentUser);
+ $group->LoadUserDefinedGroup($group_name);
+
+ if (!$group->Id) {
+ die "Unable to filter MemberOfGroup; can't load group '$group_name'";
+ }
+
+ $users->MemberOfGroup($group->Id);
+}
+
+1;
+
commit c86084ce68409286ec1969e792dffbdec87b5940
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Jul 21 14:29:49 2016 +0000
Support MemberOfGroup being specified as queue_cf
diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm b/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm
index 53954aa..05a9c49 100644
--- a/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm
@@ -9,8 +9,17 @@ sub FilterOwnersForTicket {
my $users = shift;
my $config = shift;
- my $group_name = $config->{name}
- or die "Unable to filter MemberOfGroup; no name provided.";
+ my $group_name;
+
+ if ($config->{name}) {
+ $group_name = $config->{name};
+ }
+ elsif ($config->{queue_cf}) {
+ $group_name = $ticket->QueueObj->FirstCustomFieldValue($config->{queue_cf});
+ }
+ else {
+ die "Unable to filter MemberOfGroup; no name or queue_cf provided.";
+ }
my $group = RT::Group->new($ticket->CurrentUser);
$group->LoadUserDefinedGroup($group_name);
commit 946f76831bcf67956687f3a24e07e5974c020e11
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Jul 21 14:30:08 2016 +0000
MemberOfRole filter
diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfRole.pm b/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfRole.pm
new file mode 100644
index 0000000..add30bc
--- /dev/null
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfRole.pm
@@ -0,0 +1,44 @@
+package RT::Extension::AutomaticAssignment::Filter::MemberOfRole;
+use strict;
+use warnings;
+use base 'RT::Extension::AutomaticAssignment::Filter';
+
+sub FilterOwnersForTicket {
+ my $class = shift;
+ my $ticket = shift;
+ my $users = shift;
+ my $config = shift;
+
+ my $role_name = $config->{name}
+ or die "Unable to filter MemberOfRole; no name provided.";
+
+ my ($ticket_group, $queue_group);
+
+ if ($role_name eq 'AdminCc' || $role_name eq 'Cc') {
+ $ticket_group = $ticket->RoleGroup($role_name);
+ $queue_group = $ticket->QueueObj->RoleGroup($role_name);
+ }
+ elsif ($role_name eq 'Requestor' || $role_name eq 'Requestors') {
+ $ticket_group = $ticket->RoleGroup('Requestor');
+ }
+ elsif (RT::Handle::cmp_version($RT::VERSION,'4.4.0') >= 0) {
+ die "Unable to filter MemberOfRole role '$role_name'; custom roles require RT 4.4 or greater.";
+ }
+ else {
+ my $roles = RT::CustomRoles->new( $ticket->CurrentUser );
+ $roles->Limit( FIELD => 'Name', VALUE => $role_name, CASESENSITIVE => 0 );
+ my $role = $roles->First;
+
+ $ticket_group = $ticket->RoleGroup($role->GroupType);
+ $queue_group = $ticket->QueueObj->RoleGroup($role->GroupType);
+ }
+
+ $users->WhoBelongToGroups(
+ Groups => [ map { $_->id } grep { $_ } $ticket_group, $queue_group ],
+ IncludeSubgroupMembers => 1,
+ IncludeUnprivileged => 1, # no need to LimitToPrivileged again
+ );
+}
+
+1;
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list