[Rt-commit] r17135 - in rt/3.8/branches/ruleset: lib/RT lib/RT/Approval/Rule

clkao at bestpractical.com clkao at bestpractical.com
Sun Dec 7 08:28:14 EST 2008


Author: clkao
Date: Sun Dec  7 08:28:11 2008
New Revision: 17135

Removed:
   rt/3.8/branches/ruleset/lib/RT/Approval/Rule/AllPassed.pm
Modified:
   rt/3.8/branches/ruleset/lib/RT/Approval.pm
   rt/3.8/branches/ruleset/lib/RT/Approval/Rule/Passed.pm
   rt/3.8/branches/ruleset/lib/RT/Rule.pm
   rt/3.8/branches/ruleset/t/approval/basic.t

Log:
merge allpassed rule with passed for rt::approval.


Modified: rt/3.8/branches/ruleset/lib/RT/Approval.pm
==============================================================================
--- rt/3.8/branches/ruleset/lib/RT/Approval.pm	(original)
+++ rt/3.8/branches/ruleset/lib/RT/Approval.pm	Sun Dec  7 08:28:11 2008
@@ -10,7 +10,6 @@
         'RT::Approval::Rule::NewPending',
         'RT::Approval::Rule::Rejected',
         'RT::Approval::Rule::Passed',
-        'RT::Approval::Rule::AllPassed'
     ]);
 
 1;

Modified: rt/3.8/branches/ruleset/lib/RT/Approval/Rule/Passed.pm
==============================================================================
--- rt/3.8/branches/ruleset/lib/RT/Approval/Rule/Passed.pm	(original)
+++ rt/3.8/branches/ruleset/lib/RT/Approval/Rule/Passed.pm	Sun Dec  7 08:28:11 2008
@@ -3,7 +3,7 @@
 use warnings;
 use base 'RT::Approval::Rule';
 
-use constant Description => "If an approval is rejected, reject the original and delete pending approvals"; # loc
+use constant Description => "Notify Owner of their ticket has been approved by some or all approvers"; # loc
 
 sub Prepare {
     my $self = shift;
@@ -12,28 +12,49 @@
     $self->OnStatusChange('resolved');
 }
 
-sub Commit {    # XXX: from custom prepare code
+sub Commit {
     my $self = shift;
     my $note;
     my $t = $self->TicketObj->Transactions;
+
     while ( my $o = $t->Next ) {
         $note .= $o->Content . "\n" if $o->ContentObj
                 and $o->Content !~ /Default Approval/;
     }
+    my ($Approval) = $self->TicketObj->AllDependedOnBy( Type => 'ticket' );
+    my $links  = $self->TicketObj->DependedOnBy;
+    my $passed = 0;
+
+    while ( my $link = $links->Next ) {
+        my $obj = $link->BaseObj;
+        next if ( $obj->HasUnresolvedDependencies( Type => 'approval' ) );
+
+        if ( $obj->Type eq 'ticket' ) {
+            $obj->Comment(
+                Content => $self->loc("Your request has been approved."),
+            );
+            $passed = 1;
+        }
+        elsif ( $obj->Type eq 'approval' ) {
+            $obj->SetStatus( Status => 'open', Force => 1 );
+        }
+    }
 
-    foreach my $obj ( $self->TicketObj->AllDependedOnBy( Type => 'ticket' ) ) {
-        $obj->Comment(
+    unless ($passed) {
+        $Approval->Comment(
             Content => $self->loc( "Your request has been approved by [_1]. Other approvals may still be pending.", # loc
                 $self->TransactionObj->CreatorObj->Name,
                 ) . "\n" . $self->loc( "Approver's notes: [_1]",    # loc
                 $note
                 ),
         );
-        $T::Approval = $self->TicketObj; # so we can access it inside templates
-        $self->{TicketObj} = $obj; # we want the original id in the token line
     }
 
-    $self->RunScripAction('Notify Requestors', 'Approval Passed');
+    $T::Approval = $self->TicketObj; # so we can access it inside templates
+    $self->RunScripAction('Notify Requestors',
+                          $passed ? 'All Approvals Passed' : 'Approval Passed',
+                          TicketObj => $Approval,
+                      );
 }
 
 1;

Modified: rt/3.8/branches/ruleset/lib/RT/Rule.pm
==============================================================================
--- rt/3.8/branches/ruleset/lib/RT/Rule.pm	(original)
+++ rt/3.8/branches/ruleset/lib/RT/Rule.pm	Sun Dec  7 08:28:11 2008
@@ -46,6 +46,7 @@
                                            %args,
                                        );
 
+    # XXX: fix template to allow additional arguments to be passed from here
     $action->{'TemplateObj'} = $t;
     $action->{'ScripObj'} = RT::Scrip->new($self->CurrentUser); # Stub. sendemail action really wants a scripobj available
     $action->Prepare or return;

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 08:28:11 2008
@@ -141,14 +141,14 @@
     my ($ok, $msg) = $dependson_cfo->SetStatus( Status => 'resolved' );
     ok($ok, "cfo can approve - $msg");
 
-} { from => qr/CFO via RT/,
-    to => 'minion at company.com',
-    subject => qr/Ticket Approved:/,
-    body => qr/approved by CFO/
-},{ from => qr/RT System/,
+} { from => qr/RT System/,
     to => 'ceo at company.com',
     subject => qr/New Pending Approval: PO approval request for PO/,
     body => qr/pending your approval/
+},{ from => qr/CFO via RT/,
+    to => 'minion at company.com',
+    subject => qr/Ticket Approved:/,
+    body => qr/approved by CFO/
 };
 
 is ($t->DependsOn->Count, 1, "still depends only on the CEO approval");


More information about the Rt-commit mailing list