[Rt-commit] r17142 - in rt/3.8/branches/ruleset: t/approval
clkao at bestpractical.com
clkao at bestpractical.com
Sun Dec 7 10:38:17 EST 2008
Author: clkao
Date: Sun Dec 7 10:38:17 2008
New Revision: 17142
Modified:
rt/3.8/branches/ruleset/lib/RT/Approval/Rule/Rejected.pm
rt/3.8/branches/ruleset/t/approval/basic.t
Log:
- change rejection logic so the first rejection triggers
the original ticket to be rejected (and notified by the
correct actor.)
Modified: rt/3.8/branches/ruleset/lib/RT/Approval/Rule/Rejected.pm
==============================================================================
--- rt/3.8/branches/ruleset/lib/RT/Approval/Rule/Rejected.pm (original)
+++ rt/3.8/branches/ruleset/lib/RT/Approval/Rule/Rejected.pm Sun Dec 7 10:38:17 2008
@@ -15,26 +15,29 @@
sub Commit { # XXX: from custom prepare code
my $self = shift;
-
- my $rejected = 0;
- my $links = $self->TicketObj->DependedOnBy;
+ if ( my ($rejected) =
+ $self->TicketObj->AllDependedOnBy( Type => 'ticket' ) ) {
+ my $template = RT::Template->new( $self->CurrentUser );
+ $template->Load('Approval Rejected')
+ or die;
+
+ my ( $result, $msg ) = $template->Parse(
+ TicketObj => $rejected,
+ Approval => $self->TicketObj,
+ Notes => '',
+ );
+
+ $rejected->Correspond( MIMEObj => $template->MIMEObj );
+ $rejected->SetStatus(
+ Status => 'rejected',
+ Force => 1,
+ );
+ }
+ my $links = $self->TicketObj->DependedOnBy;
foreach my $link ( @{ $links->ItemsArrayRef } ) {
my $obj = $link->BaseObj;
if ( $obj->QueueObj->IsActiveStatus( $obj->Status ) ) {
- if ( $obj->Type eq 'ticket' ) {
- $obj->Comment(
- Content => $self->loc("Your request was rejected."),
- );
- $obj->SetStatus(
- Status => 'rejected',
- Force => 1,
- );
-
- $T::Approval = $self->TicketObj; # so we can access it inside templates
- $self->{TicketObj} = $obj; # we want the original id in the token line
- $rejected = 1;
- }
- else {
+ if ( $obj->Type eq 'approval' ) {
$obj->SetStatus(
Status => 'deleted',
Force => 1,
@@ -54,8 +57,6 @@
}
}
- return $self->RunScripAction('Notify Requestors', 'Approvals Rejected')
- if $rejected;
}
1;
Modified: rt/3.8/branches/ruleset/t/approval/basic.t
==============================================================================
--- rt/3.8/branches/ruleset/t/approval/basic.t (original)
+++ rt/3.8/branches/ruleset/t/approval/basic.t Sun Dec 7 10:38:17 2008
@@ -8,7 +8,7 @@
or plan skip_all => 'require Email::Abstract and Test::Email';
}
-plan tests => 33;
+plan tests => 38;
use RT;
use RT::Test;
@@ -183,3 +183,41 @@
subject => qr/Ticket Approved:/,
body => qr/approved by CEO.*Its Owner may now start to act on it.*notes: And consumed they will be/s
};
+
+is_deeply([ $t->Status, $dependson_cfo->Status, $dependson_ceo->Status ],
+ [ 'new', 'resolved', 'resolved'], 'ticket state after ceo approval');
+
+$dependson_cfo->_Set(
+ Field => 'Status',
+ Value => 'open');
+
+$dependson_ceo->_Set(
+ Field => 'Status',
+ Value => 'new');
+
+mail_ok {
+ my $cfo = RT::CurrentUser->new;
+ $cfo->Load( $users{cfo} );
+
+ $dependson_cfo->CurrentUser($cfo);
+ my $notes = MIME::Entity->build(
+ Data => [ 'sorry, out of resources.' ]
+ );
+ RT::I18N::SetMIMEEntityToUTF8($notes); # convert text parts into utf-8
+
+# my ( $notesval, $notesmsg ) = $dependson_cfo->Correspond( MIMEObj => $notes );
+# ok($notesval, $notesmsg);
+
+ my ($ok, $msg) = $dependson_cfo->SetStatus( Status => 'rejected' );
+ ok($ok, "cfo can approve - $msg");
+
+} { from => qr/RT System/,
+ to => 'minion at company.com',
+ subject => qr/Ticket Rejected: PO for stationary/,
+ body => qr/rejected by CFO/
+};
+
+$t->Load($t->id);$dependson_ceo->Load($dependson_ceo->id);
+is_deeply([ $t->Status, $dependson_cfo->Status, $dependson_ceo->Status ],
+ [ 'rejected', 'rejected', 'deleted'], 'ticket state after cfo rejection');
+
More information about the Rt-commit
mailing list