[Bps-public-commit] r9483 - RT-Extension-SLA/lib/RT/Action

ruz at bestpractical.com ruz at bestpractical.com
Fri Oct 26 22:11:11 EDT 2007


Author: ruz
Date: Fri Oct 26 22:11:11 2007
New Revision: 9483

Modified:
   RT-Extension-SLA/lib/RT/Action/SLA_SetDue.pm

Log:
* replace LastCorrespond with 'LastRequestorsEffectiveAct'
** pretty long name, but descriptive
** returns returns txn that should be used as starting point
   for response deadline calculations
* don't treat Owner as requestor even if he is


Modified: RT-Extension-SLA/lib/RT/Action/SLA_SetDue.pm
==============================================================================
--- RT-Extension-SLA/lib/RT/Action/SLA_SetDue.pm	(original)
+++ RT-Extension-SLA/lib/RT/Action/SLA_SetDue.pm	Fri Oct 26 22:11:11 2007
@@ -43,16 +43,16 @@
 
     my $txn = $self->TransactionObj;
 
-    my $last_reply = $self->LastCorrespond;
-    $RT::Logger->debug('Last reply to ticket #'. $ticket->id .' is txn #'. $last_reply->id );
-    my $is_requestors_act = $self->IsRequestorsAct( $last_reply );
-    $RT::Logger->debug('Txn #'. $last_reply->id .' is requestors\' action') if $is_requestors_act;
+    my $last_reply = $self->LastRequestorsEffectiveAct;
+    $RT::Logger->debug('Last effective requestors\' reply to ticket #'. $ticket->id .' is txn #'. $last_reply->id )
+        if $last_reply;
 
-    my $response_due = $self->Due(
+    my $response_due;
+    $response_due = $self->Due(
         Level => $level,
         Type => 'Response',
         Time => $last_reply->CreatedObj->Unix,
-    );
+    ) if $last_reply;
 
     my $resolve_due = $self->Due(
         Level => $level,
@@ -60,10 +60,8 @@
         Time => $ticket->CreatedObj->Unix,
     );
 
-    my $type = $txn->Type;
-
     my $due;
-    $due = $response_due if defined $response_due && $is_requestors_act;
+    $due = $response_due if defined $response_due;
     $due = $resolve_due unless defined $due;
     $due = $resolve_due if defined $due && defined $resolve_due && $resolve_due < $due;
 
@@ -88,17 +86,16 @@
     my $self = shift;
     my $txn = shift || $self->TransactionObj;
 
-    return $self->TicketObj->Requestors->HasMemberRecursively(
-        $txn->CreatorObj->PrincipalObj
-    )? 1 : 0;
+    my $actor = $txn->CreatorObj->PrincipalObj;
+
+    # owner is always treated as non-requestor
+    return 0 if $actor->id == $self->TicketObj->Owner;
+
+    return $self->TicketObj->Requestors->HasMemberRecursively( $actor )? 1 : 0;
 }
 
-sub LastCorrespond {
+sub LastRequestorsEffectiveAct {
     my $self = shift;
-    
-    my $txn = $self->TransactionObj;
-    return $txn if $txn->Type eq 'Create'
-        || $txn->Type eq 'Correspond';
 
     my $txns = $self->TicketObj->Transactions;
     $txns->Limit( FIELD => 'Type', VALUE => 'Correspond' );
@@ -107,8 +104,13 @@
         { FIELD => 'Created', ORDER => 'DESC' },
         { FIELD => 'id', ORDER => 'DESC' },
     );
-    $txns->RowsPerPage(1);
-    return $txns->First;
+
+    my $res;
+    while ( my $txn = $txns->Next ) {
+        return $res unless $self->IsRequestorsAct( $txn );
+        $res = $txn;
+    }
+    return $res;
 }
 
 1;



More information about the Bps-public-commit mailing list