[Rt-commit] r9503 - in rtir/branches/2.3-EXPERIMENTAL: lib/RT/Action

ruz at bestpractical.com ruz at bestpractical.com
Tue Oct 30 11:54:31 EDT 2007


Author: ruz
Date: Tue Oct 30 11:54:30 2007
New Revision: 9503

Modified:
   rtir/branches/2.3-EXPERIMENTAL/lib/RT/Action/RTIR_SetBlockState.pm
   rtir/branches/2.3-EXPERIMENTAL/t/008-workflow-blocks.t

Log:
* fix RTIR_BlockAproveActionRegexp

Modified: rtir/branches/2.3-EXPERIMENTAL/lib/RT/Action/RTIR_SetBlockState.pm
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/lib/RT/Action/RTIR_SetBlockState.pm	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/lib/RT/Action/RTIR_SetBlockState.pm	Tue Oct 30 11:54:30 2007
@@ -65,17 +65,26 @@
         rejected => 'removed',
     );
     my $t = $self->TicketObj;
+    my $txn = $self->TransactionObj;
     my $status = $t->Status;
-    return $state{ $status } if $state{ $status };
+    my $old_state = $t->FirstCustomFieldValue('_RTIR_State');
 
-    # all code below is related to open status
+    if ( $status eq 'new' && $txn->Type eq 'Correspond' && $txn->IsInbound && $old_state eq 'pending activation' ) {
+        if ( my $re = RT->Config->Get('RTIR_BlockAproveActionRegexp') ) {
+            my $content = $txn->Content;
+            return '' if !$content || $content !~ /$re/;
+        }
+        my ($val, $msg) = $t->SetStatus( 'open' );
+        $RT::Logger->error("Couldn't change status: $msg") unless $val;
+        return 'active';
+    }
 
-    my $old_state = $t->FirstCustomFieldValue('_RTIR_State');
+    return $state{ $status } if $state{ $status };
+    # all code below is related to open status
 
     # if block was removed (resolved/rejected) we reactivate it
     return 'active' if $old_state eq 'removed';
 
-    my $txn = $self->TransactionObj;
     if ( $txn->Creator != $RT::SystemUser->id ) {
         # if a duty team member changes Status directly then we want to activate
         if ( ($txn->Type eq 'Status' || ($txn->Type eq 'Set' && $txn->Field eq 'Status')) &&

Modified: rtir/branches/2.3-EXPERIMENTAL/t/008-workflow-blocks.t
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/t/008-workflow-blocks.t	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/t/008-workflow-blocks.t	Tue Oct 30 11:54:30 2007
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Test::More tests => 62;
+use Test::More tests => 108;
 
 require "t/rtir-test.pl";
 
@@ -104,3 +104,134 @@
     ticket_state_is($agent, $block_id, 'active');
 }
 
+
+my $re = RT->Config->Get('RTIR_BlockAproveActionRegexp');
+
+SKIP: {
+    skip "RTIR_BlockAproveActionRegexp is defined", 19 if $re;
+
+    my $rtname = RT->Config->Get('rtname');
+    my $block_id = create_block( $agent, {
+        Subject => "block",
+        Incident => $inc_id,
+        Requestors => 'rt-test at example.com',
+    } );
+    ticket_state_is($agent, $block_id, 'pending activation');
+
+    {
+        my $text = <<EOF;
+From: rt-test\@example.com
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: [$rtname #$block_id] This is a test
+
+test
+EOF
+        my ($status, $id) = RT::Test->send_via_mailgate($text, queue => 'Blocks');
+        is $status >> 8, 0, "The mail gateway exited ok";
+        is $id, $block_id, "replied to the ticket";
+        ticket_state_is($agent, $block_id, 'active');
+    }
+
+    {
+        display_ticket($agent, $block_id);
+        $agent->follow_link_ok({ text => 'Pending Removal' }, "-> pending removal");
+        $agent->form_number(3);
+        $agent->field( UpdateContent => 'going to remove' );
+        $agent->click('SubmitTicket');
+        ticket_state_is($agent, $block_id, 'pending removal');
+    }
+
+    {
+        my $text = <<EOF;
+From: rt-test\@example.com
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: [$rtname #$block_id] This is a test
+
+some text
+EOF
+        my ($status, $id) = RT::Test->send_via_mailgate($text, queue => 'Blocks');
+        is $status >> 8, 0, "The mail gateway exited ok";
+        is $id, $block_id, "replied to the ticket";
+        ticket_state_is($agent, $block_id, 'removed');
+    }
+}
+
+SKIP: {
+    skip "'TestPendingBlock' doesn't match RTIR_BlockAproveActionRegexp", 27
+        unless $re && 'TestPendingBlock' =~ /$re/;
+    my $rtname = RT->Config->Get('rtname');
+    my $block_id = create_block( $agent, {
+        Subject => "block",
+        Incident => $inc_id,
+        Requestors => 'rt-test at example.com',
+    } );
+    ticket_state_is($agent, $block_id, 'pending activation');
+
+    {
+        my $text = <<EOF;
+From: rt-test\@example.com
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: [$rtname #$block_id] This is a test
+
+some text
+EOF
+        my ($status, $id) = RT::Test->send_via_mailgate($text, queue => 'Blocks');
+        is $status >> 8, 0, "The mail gateway exited ok";
+        is $id, $block_id, "replied to the ticket";
+        ticket_state_is($agent, $block_id, 'pending activation');
+    }
+
+    {
+        my $text = <<EOF;
+From: rt-test\@example.com
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: [$rtname #$block_id] This is a test
+
+TestPendingBlock
+
+EOF
+        my ($status, $id) = RT::Test->send_via_mailgate($text, queue => 'Blocks');
+        is $status >> 8, 0, "The mail gateway exited ok";
+        is $id, $block_id, "replied to the ticket";
+        ticket_state_is($agent, $block_id, 'active');
+    }
+
+    {
+        display_ticket($agent, $block_id);
+        $agent->follow_link_ok({ text => 'Pending Removal' }, "-> pending removal");
+        $agent->form_number(3);
+        $agent->field( UpdateContent => 'going to remove' );
+        $agent->click('SubmitTicket');
+        ticket_state_is($agent, $block_id, 'pending removal');
+    }
+
+    {
+        my $text = <<EOF;
+From: rt-test\@example.com
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: [$rtname #$block_id] This is a test
+
+some text
+EOF
+        my ($status, $id) = RT::Test->send_via_mailgate($text, queue => 'Blocks');
+        is $status >> 8, 0, "The mail gateway exited ok";
+        is $id, $block_id, "replied to the ticket";
+        ticket_state_is($agent, $block_id, 'pending removal');
+    }
+
+    {
+        my $text = <<EOF;
+From: rt-test\@example.com
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: [$rtname #$block_id] This is a test
+
+TestPendingBlock
+
+EOF
+        my ($status, $id) = RT::Test->send_via_mailgate($text, queue => 'Blocks');
+        is $status >> 8, 0, "The mail gateway exited ok";
+        is $id, $block_id, "replied to the ticket";
+        ticket_state_is($agent, $block_id, 'removed');
+    }
+}
+


More information about the Rt-commit mailing list