[Bps-public-commit] rt-extension-sla-utils branch, master, updated. a5d545cdec0e297aaf7044336894d4b5f051bf4f

Dave Goehrig dave at bestpractical.com
Tue Mar 21 11:27:28 EDT 2017


The branch, master has been updated
       via  a5d545cdec0e297aaf7044336894d4b5f051bf4f (commit)
      from  38573358edccd639c7358c3698fae4cba0145c78 (commit)

Summary of changes:
 .gitignore                                         |  14 +++
 etc/initialdata                                    |   6 +-
 lib/RT/Action/SLA/SetFromCustomField.pm            |  80 --------------
 lib/RT/Action/SLA/SetOverdue.pm                    |  98 -----------------
 ...tomFieldChanged.pm => SLACustomFieldChanged.pm} |  10 +-
 lib/RT/Condition/{SLA/Overdue.pm => SLAOverdue.pm} |   2 +-
 lib/RT/Extension/SLA/Utils.pm                      |  10 +-
 lib/RT/Extension/SLA/Utils/Test.pm                 | 119 ---------------------
 lib/RT/Extension/SLA/Utils/Test.pm.in              |  50 +++------
 xt/basic.t                                         |  24 ++++-
 10 files changed, 69 insertions(+), 344 deletions(-)
 create mode 100644 .gitignore
 delete mode 100644 lib/RT/Action/SLA/SetFromCustomField.pm
 delete mode 100644 lib/RT/Action/SLA/SetOverdue.pm
 rename lib/RT/Condition/{SLA/CustomFieldChanged.pm => SLACustomFieldChanged.pm} (94%)
 rename lib/RT/Condition/{SLA/Overdue.pm => SLAOverdue.pm} (98%)
 delete mode 100644 lib/RT/Extension/SLA/Utils/Test.pm

- Log -----------------------------------------------------------------
commit a5d545cdec0e297aaf7044336894d4b5f051bf4f
Author: Dave Goehrig <dave at bestpractical.com>
Date:   Mon Mar 20 10:07:29 2017 -0400

    Fixed naming issues
    
    It turns out that the Condition handler does an explicity
    query against \w+ for the name of the Condition module, which
    means modules containing :: in their name simply do not work.
    On top of that, it doesn't check the regex match for success
    so it just blows up if you supply it one.
    
    Also this module has no support for ticket creation, so setting
    the Custom Field on startup does not impact the initial value of
    the SLA, which means it will always be created with the default
    or a manual selection, and may differ from the expected if you
    set the CF on creation.
    
    Also got the tests to actually work against the database, but
    have not finished writing them.  I ran into an issue where my
    database was out of sync with my RT version.

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..adf6ee0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,14 @@
+blib*
+Makefile
+Makefile.old
+pm_to_blib*
+*.tar.gz
+.lwpcookies
+cover_db
+pod2htm*.tmp
+/RT-Extension-SLA-Utils*
+*.bak
+*.swp
+/MYMETA.*
+/t/tmp
+/xt/tmp
diff --git a/etc/initialdata b/etc/initialdata
index 49582ec..9363b3b 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -15,7 +15,7 @@ our @ScripConditions = (
         Name                 => 'On SLA Custom Field Change',
         Description          => 'The SLA Custom Field has changed',
         ApplicableTransTypes => 'CustomField',
-        ExecModule           => 'SLA::CustomFieldChanged',
+        ExecModule           => 'SLACustomFieldChanged',
     },
 );
 
@@ -23,12 +23,12 @@ our @ScripActions = (
     {
         Name                 => 'Set SLA Overdue',
         Description          => 'Set SLA Overdue custom field',
-        ExecModule           => 'SLA::SetOverdue',
+        ExecModule           => 'SLASetOverdue',
     },
     {
         Name                 => 'Set SLA Based on a Custom Field',
         Description          => 'Set the SLA based on the custom field value',
-        ExecModule           => 'SLA::SetFromCustomField',
+        ExecModule           => 'SLASetFromCustomField',
     },
 );
 
diff --git a/lib/RT/Action/SLA/SetFromCustomField.pm b/lib/RT/Action/SLA/SetFromCustomField.pm
deleted file mode 100644
index 75fdc2d..0000000
--- a/lib/RT/Action/SLA/SetFromCustomField.pm
+++ /dev/null
@@ -1,80 +0,0 @@
-# BEGIN BPS TAGGED BLOCK {{{
-#
-# COPYRIGHT:
-#
-# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
-#                                          <sales at bestpractical.com>
-#
-# (Except where explicitly superseded by other copyright notices)
-#
-#
-# LICENSE:
-#
-# This work is made available to you under the terms of Version 2 of
-# the GNU General Public License. A copy of that license should have
-# been provided with this software, but in any event can be snarfed
-# from www.gnu.org.
-#
-# This work is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 or visit their web page on the internet at
-# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
-#
-#
-# CONTRIBUTION SUBMISSION POLICY:
-#
-# (The following paragraph is not intended to limit the rights granted
-# to you to modify and distribute this software under the terms of
-# the GNU General Public License and is only of importance to you if
-# you choose to contribute your changes and enhancements to the
-# community by submitting them to Best Practical Solutions, LLC.)
-#
-# By intentionally submitting any modifications, corrections or
-# derivatives to this work, or any other work intended for use with
-# Request Tracker, to Best Practical Solutions, LLC, you confirm that
-# you are the copyright holder for those contributions and you grant
-# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
-# royalty-free, perpetual, license to use, copy, create derivative
-# works based on those contributions, and sublicense and distribute
-# those contributions and any derivatives thereof.
-#
-# END BPS TAGGED BLOCK }}}
-
-use strict;
-use warnings;
-
-package RT::Action::SLA::SetFromCustomField;
-
-use base qw(RT::Action);
-
-=head2 Prepare
-
-=cut
-
-sub Prepare {
-    return 1;
-}
-
-=head2 Commit
-
-Set SLA based on CF.
-
-=cut
-
-sub Commit {
-    my $self = shift;
-
-    my $ticket = $self->TicketObj;
-    my ($ret, $msg) = $ticket->SetSLA($self->TransactionObj->NewValue);
-    RT::Logger->error("Unable to update SLA: $msg") unless $ret;
-    return 1;
-
-}
-
-1;
diff --git a/lib/RT/Action/SLA/SetOverdue.pm b/lib/RT/Action/SLA/SetOverdue.pm
deleted file mode 100644
index 2c3c20a..0000000
--- a/lib/RT/Action/SLA/SetOverdue.pm
+++ /dev/null
@@ -1,98 +0,0 @@
-# BEGIN BPS TAGGED BLOCK {{{
-#
-# COPYRIGHT:
-#
-# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
-#                                          <sales at bestpractical.com>
-#
-# (Except where explicitly superseded by other copyright notices)
-#
-#
-# LICENSE:
-#
-# This work is made available to you under the terms of Version 2 of
-# the GNU General Public License. A copy of that license should have
-# been provided with this software, but in any event can be snarfed
-# from www.gnu.org.
-#
-# This work is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 or visit their web page on the internet at
-# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
-#
-#
-# CONTRIBUTION SUBMISSION POLICY:
-#
-# (The following paragraph is not intended to limit the rights granted
-# to you to modify and distribute this software under the terms of
-# the GNU General Public License and is only of importance to you if
-# you choose to contribute your changes and enhancements to the
-# community by submitting them to Best Practical Solutions, LLC.)
-#
-# By intentionally submitting any modifications, corrections or
-# derivatives to this work, or any other work intended for use with
-# Request Tracker, to Best Practical Solutions, LLC, you confirm that
-# you are the copyright holder for those contributions and you grant
-# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
-# royalty-free, perpetual, license to use, copy, create derivative
-# works based on those contributions, and sublicense and distribute
-# those contributions and any derivatives thereof.
-#
-# END BPS TAGGED BLOCK }}}
-
-use strict;
-use warnings;
-
-package RT::Action::SLA::SetOverdue;
-
-use base qw(RT::Action::SLA);
-
-use RT::Condition::Overdue;
-
-=head2 Prepare
-
-Checks if the ticket has service level defined.
-
-=cut
-
-sub Prepare {
-    my $self = shift;
-
-    unless ( $self->TicketObj->SLA ) {
-        $RT::Logger->error('SLA::SetOverdue scrip has been applied to ticket #'
-            . $self->TicketObj->id . ' that has no SLA defined');
-        return 0;
-    }
-
-    return 1;
-}
-
-=head2 Commit
-
-Set Overdue custom field according to SLA.
-
-=cut
-
-sub Commit {
-    my $self = shift;
-
-    my $ticket = $self->TicketObj;
-    my $txn = $self->TransactionObj;
-    my $level = $ticket->SLA;
-
-    my $overdue = RT::Condition::Overdue->new(TicketObj => $ticket);
-    return 0 unless $overdue->IsApplicable;
-
-    $ticket->AddCustomFieldValue(
-        Field => 'SLA Overdue',
-        Value => 1,
-    );
-}
-
-1;
diff --git a/lib/RT/Condition/SLA/CustomFieldChanged.pm b/lib/RT/Condition/SLACustomFieldChanged.pm
similarity index 94%
rename from lib/RT/Condition/SLA/CustomFieldChanged.pm
rename to lib/RT/Condition/SLACustomFieldChanged.pm
index 2237bf7..c7856e6 100644
--- a/lib/RT/Condition/SLA/CustomFieldChanged.pm
+++ b/lib/RT/Condition/SLACustomFieldChanged.pm
@@ -49,7 +49,7 @@
 use strict;
 use warnings;
 
-package RT::Condition::SLA::CustomFieldChanged;
+package RT::Condition::SLACustomFieldChanged;
 
 use base qw(RT::Condition);
 
@@ -70,6 +70,8 @@ Then whenever this field is changed, this condition will be met.
 
 =cut
 
+use Data::Dumper;
+
 sub IsApplicable {
     my $self = shift;
     my $txn = $self->TransactionObj;
@@ -78,6 +80,12 @@ sub IsApplicable {
 
     my $cf = RT::CustomField->new(RT->SystemUser);
     my ($ret, $msg) = $cf->Load($txn->Field);
+    
+
+    RT::Logger->debug(Dumper $txn);
+    RT::Logger->debug($ret);
+    RT::Logger->debug($msg);
+    
     RT::Logger->error("Unable to load CF for id: "
           . $txn->Field . " Error: $msg" ) unless $ret;
 
diff --git a/lib/RT/Condition/SLA/Overdue.pm b/lib/RT/Condition/SLAOverdue.pm
similarity index 98%
rename from lib/RT/Condition/SLA/Overdue.pm
rename to lib/RT/Condition/SLAOverdue.pm
index 20dd203..849a23a 100644
--- a/lib/RT/Condition/SLA/Overdue.pm
+++ b/lib/RT/Condition/SLAOverdue.pm
@@ -58,7 +58,7 @@ to help set the SLA Overdue field.
 
 =cut
 
-package RT::Condition::SLA::Overdue;
+package RT::Condition::SLAOverdue;
 use base 'RT::Condition';
 use strict;
 use warnings;
diff --git a/lib/RT/Extension/SLA/Utils.pm b/lib/RT/Extension/SLA/Utils.pm
index 7af6858..3f52671 100644
--- a/lib/RT/Extension/SLA/Utils.pm
+++ b/lib/RT/Extension/SLA/Utils.pm
@@ -74,13 +74,13 @@ SLA Levels: Low, Medium, High
 Then you don't need to define the mapping. If they are different, add configuration like:
 
     Set(%SLA_CF_Mapping,
-        '48-hour' => 'Low',
-        '24-hour' => 'Medium',
-        '8-hour'  => 'High',
+        'Low' => '48-hour',
+        'Medium' => '24-hour',
+        'High' => '8-hour',
     );
 
-where the first value is a configured SLA and the second is a valid value for the
-configured custom field.
+where the first value is a configured custom field value, and the second is the desired
+corresponding SLA.
 
 =head2 Setup rt-crontool to Run Overdue Checks
 
diff --git a/lib/RT/Extension/SLA/Utils/Test.pm b/lib/RT/Extension/SLA/Utils/Test.pm
deleted file mode 100644
index b5f36ec..0000000
--- a/lib/RT/Extension/SLA/Utils/Test.pm
+++ /dev/null
@@ -1,119 +0,0 @@
-use strict;
-use warnings;
-
-### after: use lib qw(@RT_LIB_PATH@);
-use lib qw(/Users/jbrandt/rts/rt440-test/local/lib /Users/jbrandt/rts/rt440-test/lib);
-
-package RT::Extension::SLA::Utils::Test;
-
-our @ISA;
-BEGIN {
-    local $@;
-    eval { require RT::Test; 1 } or do {
-        require Test::More;
-        Test::More::BAIL_OUT(
-            "requires 3.8 to run tests. Error:\n$@\n"
-            ."You may need to set PERL5LIB=/path/to/rt/lib"
-        );
-    };
-    push @ISA, 'RT::Test';
-}
-
-sub import {
-    my $class = shift;
-    my %args  = @_;
-
-    $args{'requires'} ||= [];
-    if ( $args{'testing'} ) {
-        unshift @{ $args{'requires'} }, 'RT::Extension::SLA::Utils';
-    } else {
-        $args{'testing'} = 'RT::Extension::SLA::Utils';
-    }
-
-    $class->SUPER::import( %args );
-    $class->export_to_level(1);
-
-    require RT::Extension::SLA::Utils;
-}
-
-sub bootstrap_more_config{
-    my $self = shift;
-    my $config = shift;
-    my $args_ref = shift;
-
-    my $sla = <<"CONFIG";
-Set(%ServiceAgreements, (
-    Default => 'Informational',
-    QueueDefault => {
-        'General' => 'Informational',
-    },
-    Levels => {
-        # The "Initial" period handled by RT::Action::SLA::SetDue
-        'Critical' => {
-            Starts      => { RealMinutes => 0     },
-            Initial     => { RealMinutes => 10    }, # Initial Response
-            FirstResponse    => { RealMinutes => 30    }, # First Response
-            KeepInLoop  => { RealMinutes => 60*1  }, # Updates
-            Resolve     => { RealMinutes => 60*4  }, # Resolution
-        },
-        'Major' => {
-            Starts      => { RealMinutes => 0     },
-            Initial     => { RealMinutes => 15    }, # Initial Response
-            FirstResponse    => { RealMinutes => 30    }, # First Response
-            KeepInLoop  => { RealMinutes => 60*24 }, # Updates
-            Resolve     => { RealMinutes => 60*48 }, # Resolution
-        },
-        'Minor' => {
-            Starts      => { RealMinutes => 0     },
-            Initial     => { RealMinutes => 60    }, # Initial Response
-            FirstResponse    => { RealMinutes => 60*2  }, # First Response
-            KeepInLoop  => { RealMinutes => 60*24 }, # Updates
-            Resolve     => { RealMinutes => 60*48 }, # Resolution
-        },
-        'Informational' => {
-            Starts      => { RealMinutes => 0     },
-            Initial     => { RealMinutes => 60    }, # Initial Response
-            FirstResponse    => { RealMinutes => 60*8  }, # First Response
-            KeepInLoop  => { RealMinutes => 60*24 }, # Updates
-            Resolve     => { RealMinutes => 60*72 }, # Resolution
-        },
-        'Trivial' => {
-         # all ignored; this level is N/A via SLAIgnoreLevels configuration value
-            Starts      => { RealMinutes => 0 },
-            Initial     => { RealMinutes => 1 },
-            FirstResponse    => { RealMinutes => 2 },
-            KeepInLoop  => { RealMinutes => 3 },
-            Resolve     => { RealMinutes => 4 },
-        }
-    },
-));
-Set(\$SLACustomField, 'Impact');
-Set(\$SLAIngnoreLevels, 'Trivial');
-CONFIG
-
-    print $config $sla;
-    
-    # Create the Impact custom field we will use for testing per the config
-    my $cf = CustomField->new(RT->SystemUser);
-    $cf->Create(
-        LookupType  => 'RT::Queue-RT::Ticket',  # for Tickets
-        Name => 'Impact',
-        Type => 'SelectSingle',  # SelectSingle is the same as: Type => 'Select', MaxValues => 1
-        RenderType  => 'Dropdown',
-        Values      => [
-            { Name => 'Critical' },
-            { Name => 'Informational' },
-            { Name => 'Major' },
-            { Name => 'Minor' },
-            { Name => 'Order to Activation' },
-        ]
-    );
-
-    my $queue = RT::Queue->new(RT->SystemUser);
-    $queue->Load('General');            # apply Impact to General queue
-    $cf->SetContextObject($queue);
-
-    return;
-}
-
-1;
diff --git a/lib/RT/Extension/SLA/Utils/Test.pm.in b/lib/RT/Extension/SLA/Utils/Test.pm.in
index d38a4c7..da389e5 100644
--- a/lib/RT/Extension/SLA/Utils/Test.pm.in
+++ b/lib/RT/Extension/SLA/Utils/Test.pm.in
@@ -6,6 +6,9 @@ use lib qw(/opt/rt4/local/lib /opt/rt4/lib);
 
 package RT::Extension::SLA::Utils::Test;
 
+use RT::CustomField;
+use RT::Queue;
+
 our @ISA;
 BEGIN {
     local $@;
@@ -43,41 +46,34 @@ sub bootstrap_more_config{
 
     my $sla = <<"CONFIG";
 Set(%ServiceAgreements, (
-    Default => 'Informational',
+    Default => 'Test-Trivial',
     QueueDefault => {
-        'General' => 'Informational',
+        'General' => 'Test-Trivial',
     },
     Levels => {
         # The "Initial" period handled by RT::Action::SLA::SetDue
-        'Critical' => {
+        'Test-Critical' => {
             Starts      => { RealMinutes => 0     },
             Initial     => { RealMinutes => 10    }, # Initial Response
             FirstResponse    => { RealMinutes => 30    }, # First Response
             KeepInLoop  => { RealMinutes => 60*1  }, # Updates
             Resolve     => { RealMinutes => 60*4  }, # Resolution
         },
-        'Major' => {
+        'Test-Major' => {
             Starts      => { RealMinutes => 0     },
             Initial     => { RealMinutes => 15    }, # Initial Response
             FirstResponse    => { RealMinutes => 30    }, # First Response
             KeepInLoop  => { RealMinutes => 60*24 }, # Updates
             Resolve     => { RealMinutes => 60*48 }, # Resolution
         },
-        'Minor' => {
+        'Test-Minor' => {
             Starts      => { RealMinutes => 0     },
             Initial     => { RealMinutes => 60    }, # Initial Response
             FirstResponse    => { RealMinutes => 60*2  }, # First Response
             KeepInLoop  => { RealMinutes => 60*24 }, # Updates
             Resolve     => { RealMinutes => 60*48 }, # Resolution
         },
-        'Informational' => {
-            Starts      => { RealMinutes => 0     },
-            Initial     => { RealMinutes => 60    }, # Initial Response
-            FirstResponse    => { RealMinutes => 60*8  }, # First Response
-            KeepInLoop  => { RealMinutes => 60*24 }, # Updates
-            Resolve     => { RealMinutes => 60*72 }, # Resolution
-        },
-        'Trivial' => {
+        'Test-Trivial' => {
          # all ignored; this level is N/A via SLAIgnoreLevels configuration value
             Starts      => { RealMinutes => 0 },
             Initial     => { RealMinutes => 1 },
@@ -87,32 +83,20 @@ Set(%ServiceAgreements, (
         }
     },
 ));
+Set(\%SLA_CF_Mapping, 
+    'Trivial' => 'Test-Trivial',
+    'Minor' => 'Test-Minor',
+    'Major' => 'Test-Major',
+    'Critical' => 'Test-Critical'
+);
+
+
 Set(\$SLACustomField, 'Impact');
 Set(\$SLAIngnoreLevels, 'Trivial');
 CONFIG
 
     print $config $sla;
     
-    # Create the Impact custom field we will use for testing per the config
-    my $cf = CustomField->new(RT->SystemUser);
-    $cf->Create(
-        LookupType  => 'RT::Queue-RT::Ticket',  # for Tickets
-        Name => 'Impact',
-        Type => 'SelectSingle',  # SelectSingle is the same as: Type => 'Select', MaxValues => 1
-        RenderType  => 'Dropdown',
-        Values      => [
-            { Name => 'Critical' },
-            { Name => 'Informational' },
-            { Name => 'Major' },
-            { Name => 'Minor' },
-            { Name => 'Order to Activation' },
-        ]
-    );
-
-    my $queue = RT::Queue->new(RT->SystemUser);
-    $queue->Load('General');            # apply Impact to General queue
-    $cf->SetContextObject($queue);
-
     return;
 }
 
diff --git a/xt/basic.t b/xt/basic.t
index 2d85ea1..c56a219 100644
--- a/xt/basic.t
+++ b/xt/basic.t
@@ -13,8 +13,9 @@ ok( $queue->SetSLADisabled(0), 'SLA enabled');
 
 
 # Create the Impact custom field we will use for testing per the config
-my $cf = RT::CustomField->new(RT->SystemUser);
-$cf->Create(
+my $ImpactCF = RT::CustomField->new(RT->SystemUser);
+my ($cfid,$msg1) = $ImpactCF->Create(
+    Queue => $queue->Id,
     LookupType  => 'RT::Queue-RT::Ticket',  # for Tickets
     Name => 'Impact',
     Type => 'SelectSingle',  # SelectSingle is the same as: Type => 'Select', MaxValues => 1
@@ -24,15 +25,30 @@ $cf->Create(
         { Name => 'Informational' },
         { Name => 'Major' },
         { Name => 'Minor' },
-        { Name => 'Order to Activation' },
+        { Name => 'Trivial' },
     ]
 );
-$cf->AddToObject($queue);
+ok $cfid, "Created Impact custom field $msg1";
 
 RT::Test->set_rights(
     Principal => 'Everyone',
     Right => ['CreateTicket', 'ShowTicket', 'SeeQueue', 'ReplyToTicket', 'ModifyTicket'],
 );
 
+my $ticket = RT::Ticket->new(RT->SystemUser);
+my ($txid,$msg2) = $ticket->Create(
+    Queue => $queue->Id,
+    Requestor => 'root at localhost',
+    Subject => 'test sla custom field change',
+); 
+ok $txid, "Created ticket $msg2";
+
+my $cfs = $ticket->CustomFields;
+is $cfs->Count, 2, "Check number of custom fields"; # Impact and SLA Overdue
+
+my ($status1,$msg3) =$ticket->AddCustomFieldValue( Field  => 'Impact', Value => 'Trivial' );
+ok $status1, "Added value Trivial $msg3";
+
+
 
 done_testing;

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


More information about the Bps-public-commit mailing list