[rt-users] Patch for approvals

Mathieu Longtin mathieu at closetwork.org
Mon Oct 26 16:37:12 EDT 2009


As I was trying to get approvals to work using the CreateTicket action and
instructions found on the wiki, I encoutered a few problems:

1. AdminCcs of ___Approvals weren't notified, because the approval action
only notified the owner. Of course, there can't be more than one owner, so
getting approval from a few people doesn't work.

2. The notice of approval said that the script was approved by "nobody",
because there was no owner of the approval request. Using a normal change
owner script didn't work, since the email was generated before the owner
change would take effect.

So I fixed that by (1) using "Notify AdminCcs" instead of "Notify Owner",
and (2) by changing the owner of the approval ticket, if it wasn't set.

The patch after the fold.

--
Mathieu Longtin
1-514-803-8977


diff -ur lib/RT/Approval/Rule/NewPending.pm
local/lib/RT/Approval/Rule/NewPending.pm
--- lib/RT/Approval/Rule/NewPending.pm  2009-08-10 14:45:44.000000000 -0400
+++ local/lib/RT/Approval/Rule/NewPending.pm    2009-10-14
15:39:13.000000000 -0400
@@ -75,7 +75,8 @@

     # first txn entry of the approval ticket
     local $self->{TransactionObj} = $to;
-    $self->RunScripAction('Notify Owner', 'New Pending Approval', @_);
+    $self->RunScripAction('Notify AdminCcs', 'New Pending Approval', @_);
+    #$self->RunScripAction('Notify Owner', 'New Pending Approval', @_);

     return;

diff -ur lib/RT/Approval/Rule/Passed.pm local/lib/RT/Approval/Rule/Passed.pm
--- lib/RT/Approval/Rule/Passed.pm      2009-08-10 14:45:44.000000000 -0400
+++ local/lib/RT/Approval/Rule/Passed.pm        2009-10-15
13:52:37.000000000 -0400
@@ -63,6 +63,19 @@
 sub Commit {
     my $self = shift;
     my $note;
+
+    # Assign approval ticket to transaction creator, if it's not owned
already
+    if ( $self->TicketObj->Owner == $RT::Nobody->id ) {
+       my $ActorObj = $self->TransactionObj->CreatorObj;
+
+       $RT::Logger->info("Auto assigning ticket #".$self->TicketObj->id."
to user ". $ActorObj->Name);
+       my ($status, $msg) = $self->TicketObj->SetOwner( $ActorObj->id );
+       unless( $status ) {
+           $RT::Logger->warning("Error assigning ticket
#".$self->TicketObj->id." to ".$ActorObj->Name.": ".$msg);
+           return undef;
+       }
+    }
+
     my $t = $self->TicketObj->Transactions;

     while ( my $o = $t->Next ) {
diff -ur lib/RT/Approval/Rule/Rejected.pm
local/lib/RT/Approval/Rule/Rejected.pm
--- lib/RT/Approval/Rule/Rejected.pm    2009-08-10 14:45:44.000000000 -0400
+++ local/lib/RT/Approval/Rule/Rejected.pm      2009-10-15
14:01:30.000000000 -0400
@@ -63,6 +63,19 @@

 sub Commit {    # XXX: from custom prepare code
     my $self = shift;
+
+    # Assign approval ticket to transaction creator, if it's not owned
already
+    if ( $self->TicketObj->Owner == $RT::Nobody->id ) {
+       my $ActorObj = $self->TransactionObj->CreatorObj;
+
+       $RT::Logger->info("Auto assigning ticket #".$self->TicketObj->id."
to user ". $ActorObj->Name);
+       my ($status, $msg) = $self->TicketObj->SetOwner( $ActorObj->id );
+       unless( $status ) {
+           $RT::Logger->warning("Error assigning ticket
#".$self->TicketObj->id." to ".$ActorObj->Name.": ".$msg);
+           return undef;
+       }
+    }
+
     if ( my ($rejected) =
         $self->TicketObj->AllDependedOnBy( Type => 'ticket' ) ) {
         my $note = '';
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20091026/11ddd0cf/attachment.htm>


More information about the rt-users mailing list