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

Shawn Moore shawn at bestpractical.com
Wed Sep 7 14:01:21 EDT 2016


The branch, master has been updated
       via  66c85dcdc8af149db898ba0fe6e6c4d633aed120 (commit)
       via  14e338389815f884a41893e55817496e7923543e (commit)
      from  ee1b99a7c4850c1a9edf1e3cf2cb3f1f23d08bb3 (commit)

Summary of changes:
 lib/RT/Extension/AutomaticAssignment.pm |   8 +--
 t/excluded-dates.t                      | 123 ++++++++++++++++++++++++++++++++
 2 files changed, 127 insertions(+), 4 deletions(-)
 create mode 100644 t/excluded-dates.t

- Log -----------------------------------------------------------------
commit 14e338389815f884a41893e55817496e7923543e
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 17:57:18 2016 +0000

    Cleanup

diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index 4081660..38f4baa 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -75,9 +75,9 @@ sub _EligibleOwnersForTicket {
         IncludeSuperusers   => 1,
     );
 
-    my @user_list = @{ $user_collection->ItemsArrayRef };
+    my $user_list = $user_collection->ItemsArrayRef;
 
-    $self->_LogFilteredUsers($ticket, \@user_list, 'after OwnTicket right check');
+    $self->_LogFilteredUsers($ticket, $user_list, 'after OwnTicket right check');
 
     for my $filter (@{ $config->{filters} }) {
         my $class = $self->_LoadedClass('Filter', $filter->{_name});
@@ -87,9 +87,9 @@ sub _EligibleOwnersForTicket {
         }
     }
 
-    $self->_LogFilteredUsers($ticket, \@user_list, 'after all filtering');
+    $self->_LogFilteredUsers($ticket, $user_list, 'after all filtering');
 
-    return \@user_list;
+    return $user_list;
 }
 
 sub _ChooseOwnerForTicket {

commit 66c85dcdc8af149db898ba0fe6e6c4d633aed120
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 17:57:31 2016 +0000

    Excluded Dates test scaffolding

diff --git a/t/excluded-dates.t b/t/excluded-dates.t
new file mode 100644
index 0000000..57b223e
--- /dev/null
+++ b/t/excluded-dates.t
@@ -0,0 +1,123 @@
+use strict;
+use warnings;
+
+use RT::Extension::AutomaticAssignment::Test tests => undef;
+use Test::MockTime 'set_fixed_time';
+
+my $queue = RT::Queue->new(RT->SystemUser);
+$queue->Load('General');
+ok($queue->Id, 'loaded General queue');
+
+my $begin = RT::CustomField->new(RT->SystemUser);
+my ($ok, $msg) = $begin->Create(
+    Name       => 'Vacation Begin',
+    LookupType => RT::User->CustomFieldLookupType,
+    Type       => 'DateTime',
+    MaxValues  => 1,
+);
+ok($ok, "created Vacation Begin CF");
+
+($ok, $msg) = $begin->AddToObject(RT::User->new(RT->SystemUser));
+ok($ok, "made Vacation Begin global");
+
+my $end = RT::CustomField->new(RT->SystemUser);
+($ok, $msg) = $end->Create(
+    Name       => 'Vacation End',
+    LookupType => RT::User->CustomFieldLookupType,
+    Type       => 'DateTime',
+    MaxValues  => 1,
+);
+ok($ok, "created Vacation End CF");
+
+($ok, $msg) = $end->AddToObject(RT::User->new(RT->SystemUser));
+ok($ok, "made Vacation End global");
+
+my $assignees = RT::Group->new(RT->SystemUser);
+$assignees->CreateUserDefinedGroup(Name => 'Assignees');
+$assignees->PrincipalObj->GrantRight(Right => 'OwnTicket', Object => $queue);
+
+($ok, $msg) = RT::Extension::AutomaticAssignment->_SetConfigForQueue(
+    $queue,
+    [
+        { ClassName => 'ExcludedDates', begin => $begin->Id, end => $end->Id },
+        { ClassName => 'MemberOfGroup', group => $assignees->Id },
+    ],
+    { ClassName => 'Random' },
+);
+ok($ok, "set AutomaticAssignment config");
+
+sub add_user {
+    my $name = shift;
+    my $begin_vacation = shift;
+    my $end_vacation = shift;
+
+    my $user = RT::User->new(RT->SystemUser);
+    my ($ok, $msg) = $user->Create(
+        Name => $name,
+    );
+    ok($ok, "created user $name");
+
+    ($ok, $msg) = $assignees->AddMember($user->Id);
+    ok($ok, "added user $name to Assignees group");
+
+    if ($begin_vacation) {
+        ($ok, $msg) = $user->AddCustomFieldValue(
+            Field => $begin->Id,
+            Value => $begin_vacation,
+        );
+        ok($ok, "added Vacation Begin $begin_vacation: $msg");
+    }
+
+    if ($end_vacation) {
+        ($ok, $msg) = $user->AddCustomFieldValue(
+            Field => $end->Id,
+            Value => $end_vacation,
+        );
+        ok($ok, "added Vacation End $end_vacation: $msg");
+    }
+
+    return $user;
+}
+
+sub eligible_ownerlist_is {
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+    my $input_time = shift;
+    my $expected = shift;
+    my $msg = shift;
+
+    my $epoch = do {
+        my $date = RT::Date->new(RT->SystemUser);
+        $date->Set(Format => 'unknown', Value => $input_time);
+        $date->Unix;
+    };
+
+    set_fixed_time($epoch);
+
+    my $ticket = RT::Ticket->new(RT->SystemUser);
+    $ticket->Create(Queue => $queue->Id);
+    ok($ticket->Id, 'created ticket');
+
+    my $got = RT::Extension::AutomaticAssignment->_EligibleOwnersForTicket(
+        $ticket,
+        undef,
+        { time => $epoch },
+    );
+
+    is_deeply(
+        [ sort map { $_->Name } @$got ],
+        [ sort @$expected ],
+        $msg,
+    );
+}
+
+eligible_ownerlist_is '2016-09-07 13:20:00' => [qw//], 'no assignees yet';
+
+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/];
+
+done_testing;
+

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


More information about the Bps-public-commit mailing list