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

Shawn Moore shawn at bestpractical.com
Thu Apr 13 17:32:51 EDT 2017


The branch, master has been updated
       via  a6bd4b152a7f676baf36035666c43507ad3b5cae (commit)
      from  bcb13799f2dd5eea55458aabfd4ba5aa6f099fb4 (commit)

Summary of changes:
 etc/AutomaticAssignment_Config.pm                  |  2 ++
 html/Admin/Queues/Elements/Chooser/UserDefined     |  9 +++++
 html/Admin/Queues/Elements/Filter/UserDefined      |  9 +++++
 .../AutomaticAssignment/Chooser/UserDefined.pm     | 29 +++++++++++++++++
 .../AutomaticAssignment/Filter/UserDefined.pm      | 38 ++++++++++++++++++++++
 static/css/automatic-assignment.css                |  4 +++
 t/compile.t                                        |  2 ++
 7 files changed, 93 insertions(+)
 create mode 100644 html/Admin/Queues/Elements/Chooser/UserDefined
 create mode 100644 html/Admin/Queues/Elements/Filter/UserDefined
 create mode 100644 lib/RT/Extension/AutomaticAssignment/Chooser/UserDefined.pm
 create mode 100644 lib/RT/Extension/AutomaticAssignment/Filter/UserDefined.pm

- Log -----------------------------------------------------------------
commit a6bd4b152a7f676baf36035666c43507ad3b5cae
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Apr 13 21:30:42 2017 +0000

    Add user-defined choosers and filters

diff --git a/etc/AutomaticAssignment_Config.pm b/etc/AutomaticAssignment_Config.pm
index 992ed6d..7dfdd81 100644
--- a/etc/AutomaticAssignment_Config.pm
+++ b/etc/AutomaticAssignment_Config.pm
@@ -3,6 +3,7 @@ Set($AutomaticAssignmentFilters, [qw(
     MemberOfGroup
     MemberOfRole
     WorkSchedule
+    UserDefined
 )]) unless $AutomaticAssignmentFilters;
 
 Set($AutomaticAssignmentChoosers, [qw(
@@ -10,6 +11,7 @@ Set($AutomaticAssignmentChoosers, [qw(
     Random
     RoundRobin
     TimeLeft
+    UserDefined
 )]) unless $AutomaticAssignmentChoosers;
 
 1;
diff --git a/html/Admin/Queues/Elements/Chooser/UserDefined b/html/Admin/Queues/Elements/Chooser/UserDefined
new file mode 100644
index 0000000..42676f9
--- /dev/null
+++ b/html/Admin/Queues/Elements/Chooser/UserDefined
@@ -0,0 +1,9 @@
+<&| /Admin/Queues/Elements/SortableBox, prefix => $prefix, is_filter => 0, class_name => 'UserDefined' &>
+<p>This chooser selects a user from the pool of eligible owners based on the provided Perl code. The variable <tt>@Users</tt> contains the list of eligible owners and <tt>$Ticket</tt> is the ticket which is being assigned. The code should return an <tt>RT::User</tt> object from the <tt>@Users</tt> array to choose that user as owner.</p>
+<textarea cols=80 rows=7 id="<% $prefix %>_code" name="<% $prefix %>_code"><% $config->{code} %></textarea>
+</&>
+<%ARGS>
+$prefix
+$config
+$queue
+</%ARGS>
diff --git a/html/Admin/Queues/Elements/Filter/UserDefined b/html/Admin/Queues/Elements/Filter/UserDefined
new file mode 100644
index 0000000..2d60446
--- /dev/null
+++ b/html/Admin/Queues/Elements/Filter/UserDefined
@@ -0,0 +1,9 @@
+<&| /Admin/Queues/Elements/SortableBox, prefix => $prefix, is_filter => 1, class_name => 'UserDefined', &>
+<p>This filter selects eligible owners based on the provided Perl code. The code is evaluated for each <tt>$User</tt>. The code should return 1 to include that user, or 0 to exclude. The variable <tt>@Users</tt> contains the list of all potential owners and <tt>$Ticket</tt> is the ticket which is being assigned.</p>
+<textarea cols=80 rows=7 id="<% $prefix %>_code" name="<% $prefix %>_code"><% $config->{code} %></textarea>
+</&>
+<%ARGS>
+$prefix
+$config
+$queue
+</%ARGS>
diff --git a/lib/RT/Extension/AutomaticAssignment/Chooser/UserDefined.pm b/lib/RT/Extension/AutomaticAssignment/Chooser/UserDefined.pm
new file mode 100644
index 0000000..6aa7672
--- /dev/null
+++ b/lib/RT/Extension/AutomaticAssignment/Chooser/UserDefined.pm
@@ -0,0 +1,29 @@
+package RT::Extension::AutomaticAssignment::Chooser::UserDefined;
+use strict;
+use warnings;
+use base 'RT::Extension::AutomaticAssignment::Chooser';
+
+sub ChooseOwnerForTicket {
+    my $class  = shift;
+    my $Ticket = shift;
+    my @Users  = @{ shift(@_) };
+    my $Config = shift;
+
+    my $user = eval $Config->{code};
+
+    return $user;
+}
+
+sub Description { "User Defined" }
+
+sub CanonicalizeConfig {
+    my $class = shift;
+    my $input = shift;
+
+    my $code = $input->{code};
+
+    return { code => $code };
+}
+
+1;
+
diff --git a/lib/RT/Extension/AutomaticAssignment/Filter/UserDefined.pm b/lib/RT/Extension/AutomaticAssignment/Filter/UserDefined.pm
new file mode 100644
index 0000000..427c9d2
--- /dev/null
+++ b/lib/RT/Extension/AutomaticAssignment/Filter/UserDefined.pm
@@ -0,0 +1,38 @@
+package RT::Extension::AutomaticAssignment::Filter::UserDefined;
+use strict;
+use warnings;
+use base 'RT::Extension::AutomaticAssignment::Filter';
+
+sub FilterOwnersForTicket {
+    my $class   = shift;
+    my $Ticket  = shift;
+    my @Users   = @{ shift(@_) };
+    my $Config  = shift;
+    my $Context = shift;
+
+    my @matches;
+
+    for my $User (@Users) {
+        push @matches, $User if eval $Config->{code};
+    }
+
+    return \@matches;
+}
+
+sub Description { "User Defined" }
+
+sub FiltersUsersArray {
+    return 1;
+}
+
+sub CanonicalizeConfig {
+    my $class = shift;
+    my $input = shift;
+
+    my $code = $input->{code};
+
+    return { code => $code };
+}
+
+1;
+
diff --git a/static/css/automatic-assignment.css b/static/css/automatic-assignment.css
index f52af01..b4ff453 100644
--- a/static/css/automatic-assignment.css
+++ b/static/css/automatic-assignment.css
@@ -53,3 +53,7 @@ form.automatic-assignment {
     height: 1em;
     width: 1em;
 }
+
+form.automatic-assignment textarea {
+    font-family: monospace;
+}
diff --git a/t/compile.t b/t/compile.t
index 9a18c77..d097411 100644
--- a/t/compile.t
+++ b/t/compile.t
@@ -13,12 +13,14 @@ use_ok('RT::Extension::AutomaticAssignment::Chooser::ActiveTickets');
 use_ok('RT::Extension::AutomaticAssignment::Chooser::Random');
 use_ok('RT::Extension::AutomaticAssignment::Chooser::RoundRobin');
 use_ok('RT::Extension::AutomaticAssignment::Chooser::TimeLeft');
+use_ok('RT::Extension::AutomaticAssignment::Chooser::UserDefined');
 
 use_ok('RT::Extension::AutomaticAssignment::Filter');
 use_ok('RT::Extension::AutomaticAssignment::Filter::ExcludedDates');
 use_ok('RT::Extension::AutomaticAssignment::Filter::MemberOfGroup');
 use_ok('RT::Extension::AutomaticAssignment::Filter::MemberOfRole');
 use_ok('RT::Extension::AutomaticAssignment::Filter::WorkSchedule');
+use_ok('RT::Extension::AutomaticAssignment::Filter::UserDefined');
 
 use_ok('RT::CustomFieldValues::ServiceBusinessHours');
 

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


More information about the Bps-public-commit mailing list