[Rt-commit] r8437 - in rtir/branches/2.3-EXPERIMENTAL: lib/RT/Action

ruz at bestpractical.com ruz at bestpractical.com
Tue Aug 7 20:29:36 EDT 2007


Author: ruz
Date: Tue Aug  7 20:29:33 2007
New Revision: 8437

Modified:
   rtir/branches/2.3-EXPERIMENTAL/etc/RTIR_Config.pm
   rtir/branches/2.3-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituency.pm

Log:
* start implementing constituency propagation algorithms

Modified: rtir/branches/2.3-EXPERIMENTAL/etc/RTIR_Config.pm
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/etc/RTIR_Config.pm	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/etc/RTIR_Config.pm	Tue Aug  7 20:29:33 2007
@@ -65,13 +65,21 @@
 Set($_RTIR_Netmask_default,             "");
 Set($_RTIR_Port_default,                "");
 Set($_RTIR_WhereBlocked_default,        "");
-Set($_RTIR_Constituency_default,        "EDUNET");
 Set($_RTIR_Function_default,            "");
 Set($_RTIR_Classification_default,      "");
 Set($_RTIR_Description_default,         "");
 Set($_RTIR_Resolution_resolved_default, "successfully resolved");
 Set($_RTIR_Resolution_rejected_default, "no resolution reached");
 
+# Constituency behaviour
+# read more about constituencies in docs/Constituency.pod
+#
+# default value
+Set( $_RTIR_Constituency_default,        "EDUNET" );
+
+# Constituency propagation algorithm
+# valid values are 'no', 'inherit', 'reject'
+Set( $_RTIR_Constituency_Propagation,    'no' );
 
 # Set the Business Hours for your organization
 # if left unset, defaults are Monday through Friday 09:00 to 18:00

Modified: rtir/branches/2.3-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituency.pm
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituency.pm	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituency.pm	Tue Aug  7 20:29:33 2007
@@ -24,21 +24,26 @@
     my $self = shift;
     my $ticket = $self->TicketObj;
 
-    my $transaction = $self->TransactionObj;
-    if ( $transaction->Type eq 'Create' ) {
+    my $type = $self->TransactionObj->Type;
+    if ( $type eq 'Create' ) {
         my $status = $self->SetConstituencyOnCreate;
         return $status if defined $status;
     }
 
-    my $constituency = $ticket->FirstCustomFieldValue('_RTIR_Constituency');
+    my $propagation = lc RT->Config->Get('_RTIR_Constituency_Propagation');
+    if ( $type eq 'AddLink' && $propagation eq 'reject' ) {
+        #XXX: check here that linked tickets have the same constituency
+    }
+
+    return 1 unless $propagation eq 'inherit';
 
-    # change owner of child Incident Reports, Investigations, Blocks
     my $query =  "( Queue = 'Incidents'"
         ." OR Queue = 'Incident Reports'"
         ." OR Queue = 'Investigations'"
         ." OR Queue = 'Blocks'"
         .")";
 
+    my $constituency = $ticket->FirstCustomFieldValue('_RTIR_Constituency');
     if ( $constituency ) {
         $query .= " AND CF.{_RTIR_Constituency} != '$constituency'";
     } else {
@@ -64,10 +69,20 @@
 sub SetConstituencyOnCreate {
     my $self = shift;
     my $ticket = $self->TicketObj;
+
     my ($current, $value);
     $current = $value = $ticket->FirstCustomFieldValue('_RTIR_Constituency');
     if ( my $tmp = $self->GetConstituencyFromParent ) {
-        $value = $tmp;
+        my $propagation = lc RT->Config->Get('_RTIR_Constituency_Propagation');
+        if ( $propagation eq 'inherit' ) {
+            $value = $tmp;
+        } elsif ( $propagation eq 'reject' && ($current||'') ne $tmp ) {
+            $RT::Logger->error(
+                "Constituency propagation algorithm is 'reject', but "
+                . "ticket ". $ticket->id ." has constituency '$current'"
+                . " when its parent incident has '$tmp'"
+            );
+        }
     }
     $value ||= $self->GetConstituencyFromAttachment;
     $value ||= RT->Config->Get('_RTIR_Constituency_default');
@@ -124,9 +139,9 @@
             $RT::Logger->crit("Couldn't load constituency field");
             return 0;
         }
-        %constituency = map { lc $_->Name => 1 } @{ $cf->Values->ItemsArrayRef };
+        %constituency = map { lc $_->Name => $_->Content } @{ $cf->Values->ItemsArrayRef };
     }
-    return exists $constituency{ lc $value };
+    return $constituency{ lc $value };
 }
 
 }


More information about the Rt-commit mailing list