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

Shawn Moore shawn at bestpractical.com
Wed Sep 7 13:10:45 EDT 2016


The branch, master has been updated
       via  ee1b99a7c4850c1a9edf1e3cf2cb3f1f23d08bb3 (commit)
       via  2348314511211d84362b43bc3d0c5d57799a2b1c (commit)
       via  a997e0422c4aa5e979a661f11fb7b2d454c9596f (commit)
       via  257702708a8c3509ba5b39445b16f61efe01efd8 (commit)
       via  a8de63be407766f63ecb2cb0b7d22049f6f7a186 (commit)
      from  380e977107adae0918447a446b6086047f9d0559 (commit)

Summary of changes:
 lib/RT/Extension/AutomaticAssignment.pm            | 80 ++++++++++------------
 .../AutomaticAssignment/Chooser/RoundRobin.pm      | 11 +--
 .../AutomaticAssignment/Filter/ExcludedDates.pm    | 24 ++++---
 .../AutomaticAssignment/Filter/WorkSchedule.pm     | 13 ++--
 4 files changed, 64 insertions(+), 64 deletions(-)

- Log -----------------------------------------------------------------
commit a8de63be407766f63ecb2cb0b7d22049f6f7a186
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 16:34:20 2016 +0000

    Move all filter logic into _EligibleOwnersForTicket

diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index 4716ca4..bea93ed 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -48,41 +48,47 @@ sub _EligibleOwnersForTicket {
     my $ticket = shift;
     my $config = shift;
 
-    my $users = RT::Users->new(RT->SystemUser);
-    $users->Limit(
+    my $user_collection = RT::Users->new(RT->SystemUser);
+    $user_collection->Limit(
         FIELD    => 'id',
         OPERATOR => 'NOT IN',
         VALUE    => [ RT->System->id, RT->Nobody->id ],
     );
 
-    $self->_LogFilteredUsers($ticket, $users, 'from initial collection');
+    $self->_LogFilteredUsers($ticket, $user_collection, 'from initial collection');
 
     for my $filter (@{ $config->{filters} }) {
         my $class = $self->_LoadedClass('Filter', $filter->{_name});
         if (!$class->FiltersUsersArray) {
-            $class->FilterOwnersForTicket($ticket, $users, $filter);
-            $self->_LogFilteredUsers($ticket, $users, $filter);
+            $class->FilterOwnersForTicket($ticket, $user_collection, $filter);
+            $self->_LogFilteredUsers($ticket, $user_collection, $filter);
         }
     }
 
-    return $users;
-}
+    # this has to come very late due to how it's implemented as replacing
+    # the collection (using rebless) with a DBIx::SearchBuilder::Union
+    $user_collection->WhoHaveRight(
+        Right               => 'OwnTicket',
+        Object              => $ticket,
+        IncludeSystemRights => 1,
+        IncludeSuperusers   => 1,
+    );
 
-sub _FilterUsersArrayForTicket {
-    my $self   = shift;
-    my $ticket = shift;
-    my $users  = shift;
-    my $config = shift;
+    my @user_list = @{ $user_collection->ItemsArrayRef };
+
+    $self->_LogFilteredUsers($ticket, \@user_list, 'after OwnTicket right check');
 
     for my $filter (@{ $config->{filters} }) {
         my $class = $self->_LoadedClass('Filter', $filter->{_name});
         if ($class->FiltersUsersArray) {
-            $users = $class->FilterOwnersForTicket($ticket, $users, $filter);
-            $self->_LogFilteredUsers($ticket, $users, $filter);
+            $user_list = $class->FilterOwnersForTicket($ticket, $user_list, $filter);
+            $self->_LogFilteredUsers($ticket, $user_list, $filter);
         }
     }
 
-    return $users;
+    $self->_LogFilteredUsers($ticket, \@user_list, 'after all filtering');
+
+    return \@user_list;
 }
 
 sub _ChooseOwnerForTicket {
@@ -203,24 +209,7 @@ sub OwnerForTicket {
     my $users = $self->_EligibleOwnersForTicket($ticket, $config);
     return if !$users;
 
-    # this has to come very late due to how it's implemented as replacing
-    # the collection (using rebless) with a DBIx::SearchBuilder::Union
-    $users->WhoHaveRight(
-        Right               => 'OwnTicket',
-        Object              => $ticket,
-        IncludeSystemRights => 1,
-        IncludeSuperusers   => 1,
-    );
-
-    my @users = @{ $users->ItemsArrayRef };
-
-    $self->_LogFilteredUsers($ticket, \@users, 'after OwnTicket right check');
-
-    @users = @{ $self->_FilterUsersArrayForTicket($ticket, \@users, $config) };
-
-    $self->_LogFilteredUsers($ticket, \@users, 'before Chooser');
-
-    my $user = $self->_ChooseOwnerForTicket($ticket, \@users, $config);
+    my $user = $self->_ChooseOwnerForTicket($ticket, $users, $config);
 
     return $user;
 }

commit 257702708a8c3509ba5b39445b16f61efe01efd8
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 16:52:25 2016 +0000

    Useful default for config if it's not provided

diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index bea93ed..5393d0d 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -46,7 +46,7 @@ sub _LogFilteredUsers {
 sub _EligibleOwnersForTicket {
     my $self   = shift;
     my $ticket = shift;
-    my $config = shift;
+    my $config = shift || $self->_ConfigForTicket($ticket);
 
     my $user_collection = RT::Users->new(RT->SystemUser);
     $user_collection->Limit(

commit a997e0422c4aa5e979a661f11fb7b2d454c9596f
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 16:54:04 2016 +0000

    Thread a context parameter throughout filters and chooser
    
        This is meant to hold the time at which automatic assignment is done.
        In the normal case, the time is "now". But for the automated tests and,
        later, in the admin UI, we want to be able to experiment with automatic
        assignment done at different times.

diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index 5393d0d..4081660 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -44,9 +44,10 @@ sub _LogFilteredUsers {
 }
 
 sub _EligibleOwnersForTicket {
-    my $self   = shift;
-    my $ticket = shift;
-    my $config = shift || $self->_ConfigForTicket($ticket);
+    my $self    = shift;
+    my $ticket  = shift;
+    my $config  = shift || $self->_ConfigForTicket($ticket);
+    my $context = shift;
 
     my $user_collection = RT::Users->new(RT->SystemUser);
     $user_collection->Limit(
@@ -60,7 +61,7 @@ sub _EligibleOwnersForTicket {
     for my $filter (@{ $config->{filters} }) {
         my $class = $self->_LoadedClass('Filter', $filter->{_name});
         if (!$class->FiltersUsersArray) {
-            $class->FilterOwnersForTicket($ticket, $user_collection, $filter);
+            $class->FilterOwnersForTicket($ticket, $user_collection, $filter, $context);
             $self->_LogFilteredUsers($ticket, $user_collection, $filter);
         }
     }
@@ -81,7 +82,7 @@ sub _EligibleOwnersForTicket {
     for my $filter (@{ $config->{filters} }) {
         my $class = $self->_LoadedClass('Filter', $filter->{_name});
         if ($class->FiltersUsersArray) {
-            $user_list = $class->FilterOwnersForTicket($ticket, $user_list, $filter);
+            $user_list = $class->FilterOwnersForTicket($ticket, $user_list, $filter, $context);
             $self->_LogFilteredUsers($ticket, $user_list, $filter);
         }
     }
@@ -92,13 +93,14 @@ sub _EligibleOwnersForTicket {
 }
 
 sub _ChooseOwnerForTicket {
-    my $self   = shift;
-    my $ticket = shift;
-    my $users  = shift;
-    my $config = shift;
+    my $self    = shift;
+    my $ticket  = shift;
+    my $users   = shift;
+    my $config  = shift;
+    my $context = shift;
 
     my $class = $self->_LoadedClass('Chooser', $config->{chooser}{_name});
-    return $class->ChooseOwnerForTicket($ticket, $users, $config->{chooser});
+    return $class->ChooseOwnerForTicket($ticket, $users, $config->{chooser}, $context);
 }
 
 sub _ConfigForTicket {
@@ -200,16 +202,17 @@ sub _ScripsForQueue {
 }
 
 sub OwnerForTicket {
-    my $self   = shift;
-    my $ticket = shift;
+    my $self    = shift;
+    my $ticket  = shift;
+    my $context = shift || {};
 
     my $config = $self->_ConfigForTicket($ticket);
     return if !$config;
 
-    my $users = $self->_EligibleOwnersForTicket($ticket, $config);
+    my $users = $self->_EligibleOwnersForTicket($ticket, $config, $context);
     return if !$users;
 
-    my $user = $self->_ChooseOwnerForTicket($ticket, $users, $config);
+    my $user = $self->_ChooseOwnerForTicket($ticket, $users, $config, $context);
 
     return $user;
 }

commit 2348314511211d84362b43bc3d0c5d57799a2b1c
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 16:55:17 2016 +0000

    Have filters consult the context for time to use

diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm b/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm
index be021de..5a401fb 100644
--- a/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm
@@ -19,13 +19,19 @@ sub _UserCF {
 }
 
 sub FilterOwnersForTicket {
-    my $class  = shift;
-    my $ticket = shift;
-    my $users  = shift;
-    my $config = shift;
-
-    my $now = RT::Date->new(RT->SystemUser);
-    $now->SetToNow;
+    my $class   = shift;
+    my $ticket  = shift;
+    my $users   = shift;
+    my $config  = shift;
+    my $context = shift;
+
+    my $time = RT::Date->new(RT->SystemUser);
+    if (exists $context->{time}) {
+        $time->Set(Format => 'unix', Value => $context->{time})
+    }
+    else {
+        $time->SetToNow;
+    }
 
     if ($config->{begin} && $config->{end}) {
         my $begin_cf = $class->_UserCF($config->{begin});
@@ -57,7 +63,7 @@ sub FilterOwnersForTicket {
             CUSTOMFIELD     => $begin_cf->Id,
             COLUMN          => 'Content',
             OPERATOR        => '>',
-            VALUE           => $now->ISO,
+            VALUE           => $time->ISO,
             ENTRYAGGREGATOR => 'OR',
         );
 
@@ -66,7 +72,7 @@ sub FilterOwnersForTicket {
             CUSTOMFIELD     => $end_cf->Id,
             COLUMN          => 'Content',
             OPERATOR        => '<',
-            VALUE           => $now->ISO,
+            VALUE           => $time->ISO,
             ENTRYAGGREGATOR => 'OR',
         );
     }
diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/WorkSchedule.pm b/lib/RT/Extension/AutomaticAssignment/Filter/WorkSchedule.pm
index 3ae05d3..40c10dd 100644
--- a/lib/RT/Extension/AutomaticAssignment/Filter/WorkSchedule.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/WorkSchedule.pm
@@ -41,12 +41,13 @@ sub FiltersUsersArray {
 }
 
 sub FilterOwnersForTicket {
-    my $class  = shift;
-    my $ticket = shift;
-    my $users  = shift;
-    my $config = shift;
+    my $class   = shift;
+    my $ticket  = shift;
+    my $users   = shift;
+    my $config  = shift;
+    my $context = shift;
 
-    my $now = time;
+    my $time = $context->{time};
 
     if ($config->{user_cf}) {
         my @eligible;
@@ -65,7 +66,7 @@ sub FilterOwnersForTicket {
             my $tz = $config->{user_tz} ? $user->Timezone : $RT::Timezone;
 
             push @eligible, $user
-                if $class->_IsTimeWithinBusinessHours($now, $args, $tz);
+                if $class->_IsTimeWithinBusinessHours($time, $args, $tz);
         }
         return \@eligible;
     }

commit ee1b99a7c4850c1a9edf1e3cf2cb3f1f23d08bb3
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 17:06:03 2016 +0000

    Have RoundRobin consult the context for dry_run

diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm
index 94264fe..69a01cd 100644
--- a/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/RoundRobin.pm
@@ -5,10 +5,11 @@ 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 $class   = shift;
+    my $ticket  = shift;
+    my @users   = @{ shift(@_) };
+    my $config  = shift;
+    my $context = shift;
 
     my $queue = $ticket->Queue;
     my $attr = 'AutomaticAssignment-RoundRobin-Queue' . $queue;
@@ -26,7 +27,7 @@ sub ChooseOwnerForTicket {
         $last_assignment{$a->Id} < $last_assignment{$b->Id} ? $a : $b
     } @users;
 
-    if ($owner) {
+    if ($owner && !$context->{dry_run}) {
         $owner->SetAttribute(Name => $attr, Content => time);
     }
 

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


More information about the Bps-public-commit mailing list