Skip to content

Commit

Permalink
- change rejection logic so the first rejection triggers
Browse files Browse the repository at this point in the history
  the original ticket to be rejected (and notified by the
  correct actor.)

git-svn-id: svn+ssh://svn.bestpractical.com/svn/bps-public/rt/3.8/branches/ruleset@17142 e417ac7c-1bcc-0310-8ffa-8f5827389a85
  • Loading branch information
Chia-liang Kao committed Dec 7, 2008
1 parent 5233790 commit 6cb8b5e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 20 deletions.
39 changes: 20 additions & 19 deletions lib/RT/Approval/Rule/Rejected.pm
Expand Up @@ -15,26 +15,29 @@ sub Prepare {

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,
Expand All @@ -54,8 +57,6 @@ sub Commit { # XXX: from custom prepare code
}
}

return $self->RunScripAction('Notify Requestors', 'Approvals Rejected')
if $rejected;
}

1;
40 changes: 39 additions & 1 deletion t/approval/basic.t
Expand Up @@ -8,7 +8,7 @@ BEGIN {
or plan skip_all => 'require Email::Abstract and Test::Email';
}

plan tests => 33;
plan tests => 38;

use RT;
use RT::Test;
Expand Down Expand Up @@ -183,3 +183,41 @@ mail_ok {
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@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');

0 comments on commit 6cb8b5e

Please sign in to comment.