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

Shawn Moore shawn at bestpractical.com
Wed Sep 7 12:15:13 EDT 2016


The branch, master has been updated
       via  380e977107adae0918447a446b6086047f9d0559 (commit)
       via  b19d83da4a9995109bb1c45e4213ef8a68ca2690 (commit)
       via  555c11bb01b44a9816b5d0155010bc74fcdf4d1f (commit)
      from  ca41f0a8ea5e96da24838e37c937ae6ba1b79cdc (commit)

Summary of changes:
 html/Admin/Queues/AutomaticAssignment.html | 43 +++++-------------------
 lib/RT/Extension/AutomaticAssignment.pm    | 53 ++++++++++++++++++++++++++++--
 t/basic.t                                  | 51 ++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 36 deletions(-)
 create mode 100644 t/basic.t

- Log -----------------------------------------------------------------
commit 555c11bb01b44a9816b5d0155010bc74fcdf4d1f
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 16:08:56 2016 +0000

    Move config canonicalization from template to lib

diff --git a/html/Admin/Queues/AutomaticAssignment.html b/html/Admin/Queues/AutomaticAssignment.html
index 8dc6893..27e49d7 100644
--- a/html/Admin/Queues/AutomaticAssignment.html
+++ b/html/Admin/Queues/AutomaticAssignment.html
@@ -99,49 +99,24 @@ my @filters = RT->Config->Get('AutomaticAssignmentFilters');
 my @choosers = RT->Config->Get('AutomaticAssignmentChoosers');
 
 if ($Update) {
-    my %queue_config;
+    my @filters_config;
+    my %chooser_config;
 
     for my $filter_prefix (split /,/, $Filters) {
         my @config_keys = grep { s/^\Q$filter_prefix\E_// ? $_ : () } keys %ARGS;
-        my %args = map { $_ => $ARGS{"${filter_prefix}_$_"} } @config_keys;
-        my $name = delete $args{ClassName};
-
-        next unless grep { $_ eq $name } RT->Config->Get('AutomaticAssignmentFilters');
-
-        my $class = "RT::Extension::AutomaticAssignment::Filter::$name";
-        unless ($class->require) {
-            RT->Logger->error("Couldn't load class '$class': $@");
-            $m->abort;
-        }
-
-        my $config = $class->CanonicalizeConfig(\%args);
-        $config->{_name} = $name;
-
-        push @{ $queue_config{filters} }, $config;
+        my %filter_config = map { $_ => $ARGS{"${filter_prefix}_$_"} } @config_keys;
+        push @filters_config, \%filter_config;
     }
 
     {
         my @config_keys = grep { s/^\Q$Chooser\E_// ? $_ : () } keys %ARGS;
-        my %args = map { $_ => $ARGS{"${Chooser}_$_"} } @config_keys;
-        my $name = delete $args{ClassName};
-
-        next unless grep { $_ eq $name } RT->Config->Get('AutomaticAssignmentChoosers');
-
-        my $class = "RT::Extension::AutomaticAssignment::Chooser::$name";
-        unless ($class->require) {
-            RT->Logger->error("Couldn't load class '$class': $@");
-            $m->abort;
-        }
-
-        my $config = $class->CanonicalizeConfig(\%args);
-        $config->{_name} = $name;
-
-        $queue_config{chooser} = $config;
+        %chooser_config = map { $_ => $ARGS{"${Chooser}_$_"} } @config_keys;
     }
 
-    my ($ok, $msg) = $QueueObj->SetAttribute(
-        Name    => 'AutomaticAssignment',
-        Content => \%queue_config,
+    my ($ok, $msg) = RT::Extension::AutomaticAssignment->_SetConfigForQueue(
+        $QueueObj,
+        \@filters_config,
+        \%chooser_config,
     );
 
     if ($ok) {
diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index cdfd7c3..71e8ef9 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -121,6 +121,55 @@ sub _ConfigForTicket {
     return $config;
 }
 
+sub _SetConfigForQueue {
+    my $self    = shift;
+    my $queue   = shift;
+    my $filters = shift;
+    my $chooser = shift;
+
+    my %config = (
+        filters => [],
+        chooser => {},
+    );
+
+    for my $filter (@$filters) {
+        my $name = delete $filter->{ClassName};
+
+        next unless grep { $_ eq $name } RT->Config->Get('AutomaticAssignmentFilters');
+
+        my $class = "RT::Extension::AutomaticAssignment::Filter::$name";
+        unless ($class->require) {
+            RT->Logger->error("Couldn't load class '$class': $@");
+            return (0, "Couldn't load class '$class'");
+        }
+
+        my $config = $class->CanonicalizeConfig($filter);
+        $config->{_name} = $name;
+
+        push @{ $config{filters} }, $config;
+    }
+
+    {
+        my $name = delete $chooser->{ClassName};
+
+        next unless grep { $_ eq $name } RT->Config->Get('AutomaticAssignmentChoosers');
+
+        my $class = "RT::Extension::AutomaticAssignment::Chooser::$name";
+        unless ($class->require) {
+            RT->Logger->error("Couldn't load class '$class': $@");
+            return (0, "Couldn't load class '$class'");
+        }
+
+        $config{chooser} = $class->CanonicalizeConfig($chooser);
+        $config{chooser}{_name} = $name;
+    }
+
+    return $queue->SetAttribute(
+        Name    => 'AutomaticAssignment',
+        Content => \%config,
+    );
+}
+
 sub _ScripsForQueue {
     my $self = shift;
     my $queue = shift;

commit b19d83da4a9995109bb1c45e4213ef8a68ca2690
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 16:14:41 2016 +0000

    Reduce log level for no automatic assignment config

diff --git a/lib/RT/Extension/AutomaticAssignment.pm b/lib/RT/Extension/AutomaticAssignment.pm
index 71e8ef9..4716ca4 100644
--- a/lib/RT/Extension/AutomaticAssignment.pm
+++ b/lib/RT/Extension/AutomaticAssignment.pm
@@ -102,7 +102,7 @@ sub _ConfigForTicket {
     my $queue = $ticket->QueueObj;
     my $attr = $queue->FirstAttribute('AutomaticAssignment');
     if (!$attr || !$attr->Content) {
-        RT->Logger->error("No AutomaticAssignment config defined; automatic assignment cannot occur.");
+        RT->Logger->debug("No AutomaticAssignment config defined; automatic assignment cannot occur.");
         return;
     }
 
@@ -114,7 +114,7 @@ sub _ConfigForTicket {
 
     # chooser is required
     if (!$config->{chooser}) {
-        RT->Logger->error("No AutomaticAssignment chooser defined for queue '$queue'; automatic assignment cannot occur.");
+        RT->Logger->debug("No AutomaticAssignment chooser defined for queue '$queue'; automatic assignment cannot occur.");
         return;
     }
 

commit 380e977107adae0918447a446b6086047f9d0559
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Wed Sep 7 16:15:03 2016 +0000

    Basic tests to ensure the machinery works

diff --git a/t/basic.t b/t/basic.t
new file mode 100644
index 0000000..9cfe906
--- /dev/null
+++ b/t/basic.t
@@ -0,0 +1,51 @@
+use strict;
+use warnings;
+
+use RT::Extension::AutomaticAssignment::Test tests => undef;
+
+my $queue = RT::Queue->new(RT->SystemUser);
+$queue->Load('General');
+ok($queue->Id, 'loaded General queue');
+
+my $root_user = RT::User->new(RT->SystemUser);
+$root_user->Load('root');
+ok($root_user->Id, 'loaded root user');
+
+my $scrip = RT::Scrip->new(RT->SystemUser); 
+my ($ok, $msg) = $scrip->Create(
+    Queue => $queue->Id,
+    ScripCondition => 'On Create',
+    ScripAction => 'Automatic Assignment',
+    Template => 'Blank',
+);
+ok($ok, "created On Create Automatic Assignment scrip");
+
+{
+    my $ticket = RT::Ticket->new(RT->SystemUser);
+    $ticket->Create(
+        Queue => $queue->Id,
+        Subject => "no automatic assignment config yet",
+    );
+    ok($ticket->Id, 'created ticket');
+    is($ticket->Owner, RT->Nobody->Id, 'no owner because no automatic assignment config yet');
+}
+
+($ok, $msg) = RT::Extension::AutomaticAssignment->_SetConfigForQueue(
+    $queue,
+    [ ], # no filters
+    { ClassName => 'Random' },
+);
+ok($ok, "set AutomaticAssignment config");
+
+{
+    my $ticket = RT::Ticket->new(RT->SystemUser);
+    $ticket->Create(
+        Queue => $queue->Id,
+        Subject => "no automatic assignment config yet",
+    );
+    ok($ticket->Id, 'created ticket');
+    is($ticket->Owner, $root_user->Id, 'automatically assigned ticket');
+}
+
+done_testing;
+

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


More information about the Bps-public-commit mailing list