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

Shawn Moore shawn at bestpractical.com
Wed Sep 7 15:37:07 EDT 2016


The branch, master has been updated
       via  0f37d4686303321d45d1cdc8b7c45e501dceeb0b (commit)
       via  08fecf310a99312bb069905c8b1781c30e0f938d (commit)
      from  66c85dcdc8af149db898ba0fe6e6c4d633aed120 (commit)

Summary of changes:
 .../AutomaticAssignment/Filter/ExcludedDates.pm    | 87 +++++++++++-----------
 lib/RT/Extension/AutomaticAssignment/Test.pm.in    |  7 ++
 t/excluded-dates.t                                 | 27 ++++++-
 3 files changed, 75 insertions(+), 46 deletions(-)

- Log -----------------------------------------------------------------
commit 08fecf310a99312bb069905c8b1781c30e0f938d
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 19:32:00 2016 +0000

    Handle "epoch" as a timestamp
    
        For the tests, the server's timezone needs to be set to UTC for the
        timezone math in RT::Date->Set(Format => 'unknown') to work out.
        Otherwise we end up with 1969-12-31 19:00:00 or some such which doesn't
        count as "unset".

diff --git a/lib/RT/Extension/AutomaticAssignment/Test.pm.in b/lib/RT/Extension/AutomaticAssignment/Test.pm.in
index c6cab16..d54ea0d 100644
--- a/lib/RT/Extension/AutomaticAssignment/Test.pm.in
+++ b/lib/RT/Extension/AutomaticAssignment/Test.pm.in
@@ -25,5 +25,12 @@ sub import {
     require RT::Extension::AutomaticAssignment;
 }
 
+sub bootstrap_more_config {
+    my $self = shift;
+    my ($config) = @_;
+
+    print $config qq|Set( \$Timezone, 'UTC' );\n|;
+}
+
 1;
 
diff --git a/t/excluded-dates.t b/t/excluded-dates.t
index 57b223e..06e29e2 100644
--- a/t/excluded-dates.t
+++ b/t/excluded-dates.t
@@ -61,6 +61,7 @@ sub add_user {
     ok($ok, "added user $name to Assignees group");
 
     if ($begin_vacation) {
+        $begin_vacation = '1970-01-01 00:00:00' if $begin_vacation eq 'epoch';
         ($ok, $msg) = $user->AddCustomFieldValue(
             Field => $begin->Id,
             Value => $begin_vacation,
@@ -69,6 +70,7 @@ sub add_user {
     }
 
     if ($end_vacation) {
+        $end_vacation = '1970-01-01 00:00:00' if $end_vacation eq 'epoch';
         ($ok, $msg) = $user->AddCustomFieldValue(
             Field => $end->Id,
             Value => $end_vacation,

commit 0f37d4686303321d45d1cdc8b7c45e501dceeb0b
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 19:33:22 2016 +0000

    Battery of tests with a newly implemented ExcludedDates

diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm b/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm
index 5a401fb..fbddc40 100644
--- a/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/ExcludedDates.pm
@@ -1,4 +1,5 @@
 package RT::Extension::AutomaticAssignment::Filter::ExcludedDates;
+use 5.10.1;
 use strict;
 use warnings;
 use base 'RT::Extension::AutomaticAssignment::Filter';
@@ -18,6 +19,10 @@ sub _UserCF {
     return $cf;
 }
 
+sub FiltersUsersArray {
+    return 1;
+}
+
 sub FilterOwnersForTicket {
     my $class   = shift;
     my $ticket  = shift;
@@ -25,56 +30,48 @@ sub FilterOwnersForTicket {
     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;
-    }
+    my $time = $context->{time} // time;
 
     if ($config->{begin} && $config->{end}) {
         my $begin_cf = $class->_UserCF($config->{begin});
         my $end_cf = $class->_UserCF($config->{end});
 
-        my $subclause = $begin_cf->Id . '-' . $end_cf->Id;
-
-        # allow users for whom begin/end is null
-        $users->LimitCustomField(
-            SUBCLAUSE       => "$subclause-begin",
-            CUSTOMFIELD     => $begin_cf->Id,
-            COLUMN          => 'Content',
-            OPERATOR        => 'IS',
-            VALUE           => 'NULL',
-        );
-        $users->LimitCustomField(
-            SUBCLAUSE       => "$subclause-end",
-            CUSTOMFIELD     => $end_cf->Id,
-            COLUMN          => 'Content',
-            OPERATOR        => 'IS',
-            VALUE           => 'NULL',
-        );
-
-        # otherwise, "now" has to be less than begin, or greater than end
-        # (expressed in the query the opposite way: begin has to be greater
-        # than now or end has to be less than now)
-        $users->LimitCustomField(
-            SUBCLAUSE       => "$subclause-begin",
-            CUSTOMFIELD     => $begin_cf->Id,
-            COLUMN          => 'Content',
-            OPERATOR        => '>',
-            VALUE           => $time->ISO,
-            ENTRYAGGREGATOR => 'OR',
-        );
-
-        $users->LimitCustomField(
-            SUBCLAUSE       => "$subclause-end",
-            CUSTOMFIELD     => $end_cf->Id,
-            COLUMN          => 'Content',
-            OPERATOR        => '<',
-            VALUE           => $time->ISO,
-            ENTRYAGGREGATOR => 'OR',
-        );
+        my @matches;
+
+        for my $user (@$users) {
+            my $begin = $user->FirstCustomFieldValue($begin_cf);
+            my $end = $user->FirstCustomFieldValue($end_cf);
+
+            # canonicalize to unix timestamp
+            if ($begin) {
+                my $date = RT::Date->new(RT->SystemUser);
+                $date->Set(Format => 'unknown', Value => $begin);
+                $begin = $date->Unix;
+            }
+
+            if ($end) {
+                my $date = RT::Date->new(RT->SystemUser);
+                $date->Set(Format => 'unknown', Value => $end);
+                $end = $date->Unix;
+            }
+
+            if ($begin && $end) {
+                next if $begin <= $time && $time <= $end;
+            }
+            elsif ($begin) {
+                next if $begin <= $time;
+            }
+            elsif ($end) {
+                next if $time <= $end;
+            }
+            else {
+                # pass through any user with no dates
+            }
+
+            push @matches, $user;
+        }
+
+        return \@matches;
     }
     else {
         die "Unable to filter ExcludedDates; both 'begin' and 'end' must be provided.";
diff --git a/t/excluded-dates.t b/t/excluded-dates.t
index 06e29e2..7325e5f 100644
--- a/t/excluded-dates.t
+++ b/t/excluded-dates.t
@@ -115,11 +115,34 @@ sub eligible_ownerlist_is {
 
 eligible_ownerlist_is '2016-09-07 13:20:00' => [qw//], 'no assignees yet';
 
+# all the new users below will be included in automatic assignment
 add_user 'NoVacation', undef, undef;
 eligible_ownerlist_is '2016-09-07 13:20:00' => [qw/NoVacation/];
 
 add_user 'AfterVacation', '2015-01-01 00:00:00', '2015-01-10 00:00:00';
-eligible_ownerlist_is '2016-09-07 13:20:00' => [qw/NoVacation AfterVacation/];
+add_user 'UpcomingVacation', '2017-01-01 00:00:00', '2017-01-10 00:00:00';
+eligible_ownerlist_is '2016-09-07 13:20:00' => [qw/NoVacation AfterVacation UpcomingVacation/];
+
+add_user 'Leaving', '2016-10-01 00:00:00', undef;
+add_user 'Started', undef, '2016-01-01 00:00:00';
+eligible_ownerlist_is '2016-09-07 13:20:00' => [qw/NoVacation AfterVacation UpcomingVacation Leaving Started/];
+
+add_user 'EpochNoVacation', 'epoch', 'epoch';
+add_user 'EpochLeaving', '2016-10-01 00:00:00', 'epoch';
+add_user 'EpochStarted', 'epoch', '2016-01-01 00:00:00';
+eligible_ownerlist_is '2016-09-07 13:20:00' => [qw/NoVacation AfterVacation UpcomingVacation Leaving Started EpochNoVacation EpochLeaving EpochStarted/];
+
+# all the new users below will not be included in automatic assignment
+add_user 'OnVacation', '2016-09-01 00:00:00', '2016-09-15 00:00:00';
+eligible_ownerlist_is '2016-09-07 13:20:00' => [qw/NoVacation AfterVacation UpcomingVacation Leaving Started EpochNoVacation EpochLeaving EpochStarted/];
+
+add_user 'Left', '2016-03-01 00:00:00', undef;
+add_user 'EpochLeft', '2016-03-01 00:00:00', 'epoch';
+eligible_ownerlist_is '2016-09-07 13:20:00' => [qw/NoVacation AfterVacation UpcomingVacation Leaving Started EpochNoVacation EpochLeaving EpochStarted/];
+
+add_user 'WillStart', undef, '2016-10-01 00:00:00';
+add_user 'EpochWillStart', 'epoch', '2016-10-01 00:00:00';
+eligible_ownerlist_is '2016-09-07 13:20:00' => [qw/NoVacation AfterVacation UpcomingVacation Leaving Started EpochNoVacation EpochLeaving EpochStarted/];
 
 done_testing;
 

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


More information about the Bps-public-commit mailing list