[Bps-public-commit] rt-extension-automaticassignment branch, master, updated. a48165f1198aa095811231d6180a5a4926cd9b50

Shawn Moore shawn at bestpractical.com
Wed Aug 10 20:32:39 EDT 2016


The branch, master has been updated
       via  a48165f1198aa095811231d6180a5a4926cd9b50 (commit)
       via  72ee9ade7677561fbb5ed3f2efb15088d9a7073e (commit)
      from  285aaf75b68e8ec55a04814acfd976bce737ab19 (commit)

Summary of changes:
 html/Helpers/AddFilter                             |  2 +-
 html/Helpers/SelectChooser                         |  2 +-
 lib/RT/Extension/AutomaticAssignment.pm            | 52 ++++------------------
 .../AutomaticAssignment/Filter/ExcludedDates.pm    |  2 +-
 .../AutomaticAssignment/Filter/MemberOfGroup.pm    |  1 +
 .../AutomaticAssignment/Filter/MemberOfRole.pm     | 24 +++++-----
 .../AutomaticAssignment/Filter/WorkSchedule.pm     | 17 -------
 7 files changed, 22 insertions(+), 78 deletions(-)

- Log -----------------------------------------------------------------
commit 72ee9ade7677561fbb5ed3f2efb15088d9a7073e
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Aug 11 00:17:17 2016 +0000

    Validate Name against config rather than /^\w+$/

diff --git a/html/Helpers/AddFilter b/html/Helpers/AddFilter
index 7834496..dd5a973 100644
--- a/html/Helpers/AddFilter
+++ b/html/Helpers/AddFilter
@@ -4,7 +4,7 @@ $i => 0
 $Queue => undef
 </%ARGS>
 <%INIT>
-$m->abort if !$Name || $Name =~ /\W/;
+$m->abort unless grep { $Name eq $_ } RT->Config->Get('AutomaticAssignmentFilters');
 
 my $QueueObj = RT::Queue->new($session{'CurrentUser'});
 $QueueObj->Load( $Queue );
diff --git a/html/Helpers/SelectChooser b/html/Helpers/SelectChooser
index e143775..17071c2 100644
--- a/html/Helpers/SelectChooser
+++ b/html/Helpers/SelectChooser
@@ -3,7 +3,7 @@ $Name => undef
 $Queue => undef
 </%ARGS>
 <%INIT>
-$m->abort if !$Name || $Name =~ /\W/;
+$m->abort unless grep { $Name eq $_ } RT->Config->Get('AutomaticAssignmentChoosers');
 
 my $QueueObj = RT::Queue->new($session{'CurrentUser'});
 $QueueObj->Load( $Queue );

commit a48165f1198aa095811231d6180a5a4926cd9b50
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Aug 11 00:20:13 2016 +0000

    Simplify config loading now that it's consistently generated by admin UI

diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index 5533271..974e5e2 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -15,7 +15,7 @@ sub _LoadedClass {
     my $namespace = shift;
     my $name      = shift;
 
-    my $class = $name =~ /::/ ? $name : "RT::Extension::AutomaticAssignment::${namespace}::$name";
+    my $class = "RT::Extension::AutomaticAssignment::${namespace}::$name";
     $class->require or die $UNIVERSAL::require::ERROR;
     return $class;
 }
@@ -43,14 +43,9 @@ sub _EligibleOwnersForTicket {
     );
 
     for my $filter (@{ $config->{filters} }) {
-        if (ref($filter) eq 'CODE') {
-            $filter->($users, $ticket);
-        }
-        else {
-            my $class = $filter->{class};
-            $class->FilterOwnersForTicket($ticket, $users, $filter)
-                if !$class->FiltersUsersArray;
-        }
+        my $class = $self->_LoadedClass('Filter', $filter->{_name});
+        $class->FilterOwnersForTicket($ticket, $users, $filter)
+            if !$class->FiltersUsersArray;
     }
 
     return $users;
@@ -63,15 +58,9 @@ sub _FilterUsersArrayForTicket {
     my $config = shift;
 
     for my $filter (@{ $config->{filters} }) {
-        if (ref($filter) eq 'CODE') {
-            next;
-        }
-        else {
-            my $class = $filter->{class};
-            next unless $class->FiltersUsersArray;
-
-            $users = $class->FilterOwnersForTicket($ticket, $users, $filter);
-        }
+        my $class = $self->_LoadedClass('Filter', $filter->{_name});
+        $users = $class->FilterOwnersForTicket($ticket, $users, $filter)
+            if $class->FiltersUsersArray;
     }
 
     return $users;
@@ -83,7 +72,7 @@ sub _ChooseOwnerForTicket {
     my $users  = shift;
     my $config = shift;
 
-    my $class = $config->{chooser}{class};
+    my $class = $self->_LoadedClass('Chooser', $config->{chooser}{_name});
     return $class->ChooseOwnerForTicket($ticket, $users, $config->{chooser});
 }
 
@@ -110,31 +99,6 @@ sub _ConfigForTicket {
         return;
     }
 
-    # load each filter class
-    for (@{ $config->{filters} }) {
-        if (!ref($_)) {
-            $_ = {
-                class => $self->_LoadedClass('Filter', $_),
-            };
-        }
-        elsif (ref($_) eq 'CODE') {
-            # nothing to do
-        }
-        else {
-            $_->{class} = $self->_LoadedClass('Filter', $_->{class});
-        }
-    }
-
-    # load chooser class
-    if (!ref($config->{chooser})) {
-        $config->{chooser} = {
-            class => $self->_LoadedClass('Chooser', $config->{chooser}),
-        };
-    }
-    else {
-        $config->{chooser}{class} = $self->_LoadedClass('Chooser', $config->{chooser}{class});
-    }
-
     return $config;
 }
 
diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm b/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm
index f87a7a5..be021de 100644
--- a/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm
@@ -71,7 +71,7 @@ sub FilterOwnersForTicket {
         );
     }
     else {
-        die "Unable to filter ExcludedDates; no 'except_between' provided.";
+        die "Unable to filter ExcludedDates; both 'begin' and 'end' must be provided.";
     }
 }
 
diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm b/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm
index daa0b6a..7e396fe 100644
--- a/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfGroup.pm
@@ -30,5 +30,6 @@ sub CanonicalizeConfig {
 
     return { group => $group };
 }
+
 1;
 
diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfRole.pm b/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfRole.pm
index 7c465eb..a9c2028 100644
--- a/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfRole.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/MemberOfRole.pm
@@ -9,28 +9,24 @@ sub FilterOwnersForTicket {
     my $users  = shift;
     my $config = shift;
 
-    my $role_name = $config->{name}
-        or die "Unable to filter MemberOfRole; no name provided.";
+    my $role = $config->{role}
+        or die "Unable to filter MemberOfRole; no role 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');
+    if ($role eq 'AdminCc' || $role eq 'Cc' || $role eq 'Requestor') {
+        $ticket_group = $ticket->RoleGroup($role);
+        $queue_group = $ticket->QueueObj->RoleGroup($role);
     }
     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.";
+        die "Unable to filter MemberOfRole role '$role'; 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;
+        my $customrole = RT::CustomRole->new( $ticket->CurrentUser );
+        $customrole->Load($role);
 
-        $ticket_group = $ticket->RoleGroup($role->GroupType);
-        $queue_group = $ticket->QueueObj->RoleGroup($role->GroupType);
+        $ticket_group = $ticket->RoleGroup($customrole->GroupType);
+        $queue_group = $ticket->QueueObj->RoleGroup($customrole->GroupType);
     }
 
     $users->WhoBelongToGroups(
diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/WorkSchedule.pm b/lib/RT/Extension/AutomaticAssignment/Filter/WorkSchedule.pm
index 0a6a2a4..3ae05d3 100644
--- a/lib/RT/Extension/AutomaticAssignment/Filter/WorkSchedule.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/WorkSchedule.pm
@@ -4,21 +4,6 @@ use warnings;
 use base 'RT::Extension::AutomaticAssignment::Filter';
 use Business::Hours;
 
-sub _UserCF {
-    my $class = shift;
-    my $id    = shift;
-
-    my $cf = RT::CustomField->new(RT->SystemUser);
-    $cf->LoadByCols(
-        id         => $id,
-        LookupType => RT::User->CustomFieldLookupType,
-    );
-    if (!$cf->Id) {
-        die "Unable to load User Custom Field '$id'";
-    }
-    return $cf;
-}
-
 sub _IsTimeWithinBusinessHours {
     my $class  = shift;
     my $time   = shift;
@@ -64,8 +49,6 @@ sub FilterOwnersForTicket {
     my $now = time;
 
     if ($config->{user_cf}) {
-        $class->_UserCF($config->{user_cf}); # validate user CF exists
-
         my @eligible;
         for my $user (@$users) {
             my $schedule = $user->FirstCustomFieldValue($config->{user_cf});

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


More information about the Bps-public-commit mailing list