[Rt-commit] r5748 - in RT-Action-LinearEscalate: . t

kevinr at bestpractical.com kevinr at bestpractical.com
Wed Aug 9 19:54:21 EDT 2006


Author: kevinr
Date: Wed Aug  9 19:54:20 2006
New Revision: 5748

Added:
   RT-Action-LinearEscalate/t/workflow.t
Modified:
   RT-Action-LinearEscalate/   (props changed)
   RT-Action-LinearEscalate/lib/RT/Action/LinearEscalate.pm

Log:
 r17977 at sad-girl-in-snow:  kevinr | 2006-08-09 19:52:19 -0400
 * Added two configuration directives, $RT::LinearEscalate_RecordTransaction and
 $RT::LinearEscalate_UpdateLastUpdated, to give users better control of how
 visible their escalations are.  Also, tests.


Modified: RT-Action-LinearEscalate/lib/RT/Action/LinearEscalate.pm
==============================================================================
--- RT-Action-LinearEscalate/lib/RT/Action/LinearEscalate.pm	(original)
+++ RT-Action-LinearEscalate/lib/RT/Action/LinearEscalate.pm	Wed Aug  9 19:54:20 2006
@@ -74,6 +74,15 @@
     "(Status='new' OR Status='open' OR Status = 'stalled')" \
     --action RT::Action::LinearEscalate
 
+LinearEscalate's behavior can be controlled by two configuration options
+set in RT_SiteConfig.pm -- LinearEscalate_RecordTransaction, which 
+defaults to false and causes the tool to create a transaction on the 
+ticket when it is escalated, and LinearEscalate_UpdateLastUpdated, which 
+defaults to true and updates the LastUpdated field when the ticket is 
+escalated.  You cannot set LinearEscalate_UpdateLastUpdated to false 
+unless LinearEscalate_RecordTransaction is also false.  (Well, you can,
+but we'll just ignore you.)
+
 
 =cut
 
@@ -84,8 +93,13 @@
 use base qw(RT::Action::Generic);
 
 our $VERSION = '0.01';
-$RT::EscalateSilently = 1;
 
+my $RecordTransaction = ( defined $RT::LinearEscalate_RecordTransaction 
+                            ? $RT::LinearEscalate_RecordTransaction : 0 
+                        );
+my $UpdateLastUpdated = ( defined $RT::LinearEscalate_UpdateLastUpdated 
+                            ? $RT::LinearEscalate_UpdateLastUpdated : 1
+                        );
 
 #Do what we need to do and send it out.
 
@@ -182,11 +196,28 @@
 sub Commit {
     my $self = shift;
     my ( $val, $msg );
-    if ($RT::EscalateSilently) {
-        ( $val, $msg ) = $self->TicketObj->_Set( Field => 'Priority',
-                                                 Value => $self->{'prio'},
-                                                 RecordTransaction => 0,
-                                                );
+
+    #testing purposes only, it's a dirty ugly hack
+    $self->Argument =~ /RecordTransaction:(\d); UpdateLastUpdated:(\d)/;
+    $RecordTransaction = (defined $1 ? $1 : $RecordTransaction);
+    $UpdateLastUpdated = (defined $2 ? $2 : $UpdateLastUpdated);
+    $RT::Logger->warning("Overrode RecordTransaction: $RecordTransaction") 
+        if defined $1;
+    $RT::Logger->warning("Overrode UpdateLastUpdated: $UpdateLastUpdated") 
+        if defined $2;
+
+    unless ($RecordTransaction) {
+        unless ($UpdateLastUpdated) {
+            ( $val, $msg ) = $self->TicketObj->__Set( Field => 'Priority',
+                                                      Value => $self->{'prio'},
+                                                     );
+        }
+        else {
+            ( $val, $msg ) = $self->TicketObj->_Set( Field => 'Priority',
+                                                     Value => $self->{'prio'},
+                                                     RecordTransaction => 0,
+                                                    );
+        }
     }
     else {
         ( $val, $msg ) = $self->TicketObj->SetPriority( $self->{'prio'} );

Added: RT-Action-LinearEscalate/t/workflow.t
==============================================================================
--- (empty file)
+++ RT-Action-LinearEscalate/t/workflow.t	Wed Aug  9 19:54:20 2006
@@ -0,0 +1,97 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Test::More qw/no_plan/;
+
+use RT;
+RT::LoadConfig;
+RT::Init;
+
+my ($id, $msg);
+my $RecordTransaction;
+my $UpdateLastUpdated;
+
+
+use_ok('RT::Action::LinearEscalate');
+use RT::Action::LinearEscalate;
+
+my $queue_name = "EscalationTest$$"; 
+my $queue = RT::Queue->new($RT::SystemUser);
+($id, $msg) = $queue->Create( Name => $queue_name );
+ok( $id, "Created queue? $msg");
+
+my $user_name = "suer$$";
+my $user = RT::User->new($RT::SystemUser);
+($id, $msg) = $user->Create( Name => $user_name );
+ok( $id, "Created user? $msg");
+($id, $msg) = $user->SetPrivileged(1);
+ok( $id, "Made user privileged? $msg" );
+$user->PrincipalObj->GrantRight( Right => 'SuperUser' );
+ok( $id, "Made user a SuperUser? $msg" );
+my $current_user = RT::CurrentUser->new($RT::SystemUser);
+($id, $msg) = $current_user->Load($user->id);
+ok( $id, "Got current user? $msg" );
+
+
+#defaults
+$RecordTransaction = 0;
+$UpdateLastUpdated = 1;
+my $ticket2 = create_ticket_as_ok($current_user);
+escalate_ticket_ok($ticket2);
+ok( $ticket2->LastUpdatedBy != $user->id, "Set LastUpdated" );
+ok( $ticket2->Transactions->Last->Type =~ /Create/i, "Did not record a transaction" );
+
+$RecordTransaction = 1;
+$UpdateLastUpdated = 1;
+my $ticket1 = create_ticket_as_ok($current_user);
+escalate_ticket_ok($ticket1);
+ok( $ticket1->LastUpdatedBy != $user->id, "Set LastUpdated" );
+ok( $ticket1->Transactions->Last->Type !~ /Create/i, "Recorded a transaction" );
+
+$RecordTransaction = 0;
+$UpdateLastUpdated = 0;
+my $ticket3 = create_ticket_as_ok($current_user);
+escalate_ticket_ok($ticket3);
+ok( $ticket3->LastUpdatedBy == $user->id, "Did not set LastUpdated" );
+ok( $ticket3->Transactions->Last->Type =~ /Create/i, "Did not record a transaction" );
+
+1;
+
+
+sub create_ticket_as_ok {
+    my $user = shift;
+
+    my $created = RT::Date->new($RT::SystemUser);
+    $created->Unix(time() - ( 7 * 24 * 60**2 ));
+    my $due = RT::Date->new($RT::SystemUser);
+    $due->Unix(time() + ( 7 * 24 * 60**2 ));
+
+    my $ticket = RT::Ticket->new($user);
+    ($id, $msg) = $ticket->Create( Queue => $queue_name,
+                                   Subject => "Escalation test",
+                                   Priority => 0,
+                                   InitialPriority => 0,
+                                   FinalPriority => 50,
+                                 );
+    ok($id, "Created ticket? ".$id);
+    $ticket->__Set( Field => 'Created',
+                    Value => $created->ISO,
+                  );
+    $ticket->__Set( Field => 'Due',
+                    Value => $due->ISO,
+                  );
+
+    return $ticket;
+}
+
+sub escalate_ticket_ok {
+    my $ticket = shift;
+    my $id = $ticket->id;
+    print "rt-crontool --search RT::Search::FromSQL --search-arg \"id = @{[$id]}\" --action RT::Action::LinearEscalate --action-arg \"RecordTransaction:$RecordTransaction; UpdateLastUpdated:$UpdateLastUpdated\"\n";
+    print STDERR `rt-crontool --search RT::Search::FromSQL --search-arg "id = @{[$id]}" --action RT::Action::LinearEscalate --action-arg "RecordTransaction:$RecordTransaction; UpdateLastUpdated:$UpdateLastUpdated"`;
+
+    $ticket->Load($id);     # reload, because otherwise we get the cached value
+    ok( $ticket->Priority != 0, "Escalated ticket" );
+}


More information about the Rt-commit mailing list