[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.8-136-g702cdf8

? sunnavy sunnavy at bestpractical.com
Wed Aug 18 03:30:07 EDT 2010


The branch, 3.8-trunk has been updated
       via  702cdf8b45cdd04b54d57ab650e9b7e1164798fa (commit)
      from  3adb6b75ae2601faea3d33ad5b2f9ec43f72dbee (commit)

Summary of changes:
 lib/RT/Scrip_Overlay.pm |   60 ++++++++++++++++++++++++++++++++++++++
 t/api/scrip.t           |   74 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 133 insertions(+), 1 deletions(-)

- Log -----------------------------------------------------------------
commit 702cdf8b45cdd04b54d57ab650e9b7e1164798fa
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Aug 18 15:01:46 2010 +0800

    make sure scrip not updated with invalid action/condition/template

diff --git a/lib/RT/Scrip_Overlay.pm b/lib/RT/Scrip_Overlay.pm
index f31f1dc..b6a2130 100755
--- a/lib/RT/Scrip_Overlay.pm
+++ b/lib/RT/Scrip_Overlay.pm
@@ -584,5 +584,65 @@ sub HasRight {
 
 # }}}
 
+
+=head2 SetScripAction
+
+=cut
+
+sub SetScripAction {
+    my $self  = shift;
+    my $value = shift;
+
+    return ( 0, $self->loc("Action is mandatory argument") ) unless $value;
+
+    require RT::ScripAction;
+    my $action = RT::ScripAction->new( $self->CurrentUser );
+    $action->Load($value);
+    return ( 0, $self->loc( "Action '[_1]' not found", $value ) )
+      unless $action->Id;
+
+    return $self->_Set( Field => 'ScripAction', Value => $value );
+}
+
+=head2 SetScripCondition
+
+=cut
+
+sub SetScripCondition {
+    my $self  = shift;
+    my $value = shift;
+
+    return ( 0, $self->loc("Condition is mandatory argument") )
+      unless $value;
+
+    require RT::ScripCondition;
+    my $condition = RT::ScripCondition->new( $self->CurrentUser );
+    $condition->Load($value);
+
+    return ( 0, $self->loc( "Condition '[_1]' not found", $value ) )
+      unless $condition->Id;
+
+    return $self->_Set( Field => 'ScripCondition', Value => $value );
+}
+
+=head2 SetTemplate
+
+=cut
+
+sub SetTemplate {
+    my $self  = shift;
+    my $value = shift;
+
+    return ( 0, $self->loc("Template is mandatory argument") ) unless $value;
+
+    require RT::Template;
+    my $template = RT::Template->new( $self->CurrentUser );
+    $template->Load($value);
+    return ( 0, $self->loc( "Template '[_1]' not found", $value ) )
+      unless $template->Id;
+
+    return $self->_Set( Field => 'Template', Value => $value );
+}
+
 1;
 
diff --git a/t/api/scrip.t b/t/api/scrip.t
index 8e8f962..9d97e73 100644
--- a/t/api/scrip.t
+++ b/t/api/scrip.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 use RT;
-use RT::Test tests => 7;
+use RT::Test tests => 25;
 
 
 {
@@ -46,4 +46,76 @@ isnt ($ticket2->Priority , '87', "Ticket priority is set right");
 
 }
 
+
+{
+    my $scrip = RT::Scrip->new($RT::SystemUser);
+    my ( $val, $msg ) = $scrip->Create(
+        ScripCondition => 'On Comment',
+        ScripAction    => 'Notify Owner',
+    );
+    ok( !$val, "missing template: $msg" );
+    ( $val, $msg ) = $scrip->Create(
+        ScripCondition => 'On Comment',
+        ScripAction    => 'Notify Owner',
+        Template       => 'not exists',
+    );
+    ok( !$val, "invalid template: $msg" );
+
+    ( $val, $msg ) = $scrip->Create(
+        ScripAction => 'Notify Owner',
+        Template    => 'Blank',
+    );
+    ok( !$val, "missing condition: $msg" );
+    ( $val, $msg ) = $scrip->Create(
+        ScripCondition => 'not exists',
+        ScripAction    => 'Notify Owner',
+        Template       => 'Blank',
+    );
+    ok( !$val, "invalid condition: $msg" );
+
+    ( $val, $msg ) = $scrip->Create(
+        ScripCondition => 'On Comment',
+        Template       => 'Blank',
+    );
+    ok( !$val, "missing action: $msg" );
+    ( $val, $msg ) = $scrip->Create(
+        ScripCondition => 'On Comment',
+        ScripAction    => 'not exists',
+        Template       => 'Blank',
+    );
+    ok( !$val, "invalid action: $msg" );
+
+    ( $val, $msg ) = $scrip->Create(
+        ScripAction    => 'Notify Owner',
+        ScripCondition => 'On Comment',
+        Template       => 'Blank',
+    );
+    ok( $val, "created scrip: $msg" );
+    $scrip->Load($val);
+    ok( $scrip->id, 'loaded scrip ' . $scrip->id );
+
+    ( $val, $msg ) = $scrip->SetScripCondition();
+    ok( !$val, "missing condition: $msg" );
+    ( $val, $msg ) = $scrip->SetScripCondition('not exists');
+    ok( !$val, "invalid condition: $msg" );
+    ( $val, $msg ) = $scrip->SetScripCondition('On Correspond');
+    ok( $val, "updated condition to 'On Correspond': $msg" );
+
+    ( $val, $msg ) = $scrip->SetScripAction();
+    ok( !$val, "missing action: $msg" );
+    ( $val, $msg ) = $scrip->SetScripAction('not exists');
+    ok( !$val, "invalid action: $msg" );
+    ( $val, $msg ) = $scrip->SetScripAction('Notify AdminCcs');
+    ok( $val, "updated action to 'Notify AdminCcs': $msg" );
+
+    ( $val, $msg ) = $scrip->SetTemplate();
+    ok( !$val, "missing template $msg" );
+    ( $val, $msg ) = $scrip->SetTemplate('not exists');
+    ok( !$val, "invalid template $msg" );
+    ( $val, $msg ) = $scrip->SetTemplate('Forward');
+    ok( $val, "updated template to 'Forward': $msg" );
+
+    ok( $scrip->Delete, 'delete the scrip' );
+}
+
 1;

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


More information about the Rt-commit mailing list