[Rt-commit] r10035 - in rtir/branches/2.3-EXPERIMENTAL:
lib/RT/Action
ruz at bestpractical.com
ruz at bestpractical.com
Fri Dec 21 09:16:12 EST 2007
Author: ruz
Date: Fri Dec 21 09:16:12 2007
New Revision: 10035
Modified:
rtir/branches/2.3-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituency.pm
rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t
Log:
8 on linking prefer parent's constituency
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 Fri Dec 21 09:16:12 2007
@@ -35,7 +35,15 @@
#XXX: check here that linked tickets have the same constituency
}
- return 1 unless $propagation eq 'inherit';
+ return $self->InheritConstituency if $propagation eq 'inherit';
+
+ return 1;
+
+}
+
+sub InheritConstituency {
+ my $self = shift;
+ my $ticket = $self->TicketObj;
my $query = "( Queue = 'Incidents'"
." OR Queue = 'Incident Reports'"
@@ -50,7 +58,24 @@
$query .= " AND CF.{_RTIR_Constituency} IS NOT NULL";
}
- # do two queries as mysql couldn't optimize things well
+ my $type = $self->TransactionObj->Type;
+ if ( $type eq 'AddLink' ) {
+ # inherit from parent on linking
+ my $tickets = RT::Tickets->new( $RT::SystemUser );
+ $tickets->FromSQL( $query ." AND HasMember = ". $ticket->Id );
+ $tickets->RowsPerPage( 1 );
+ if ( my $parent = $tickets->First ) {
+ $RT::Logger->debug( "Ticket #". $ticket->id ." inherits constituency from ticket #". $parent->id );
+ my ($res, $msg) = $ticket->AddCustomFieldValue(
+ Field => '_RTIR_Constituency',
+ Value => $constituency,
+ );
+ $RT::Logger->warning( "Couldn't set CF: $msg" ) unless $res;
+ return 1;
+ }
+ }
+
+ # propagate to members
foreach my $link_type (qw(MemberOf HasMember)) {
my $tickets = RT::Tickets->new( $RT::SystemUser );
$tickets->FromSQL( $query ." AND $link_type = ". $ticket->Id );
Modified: rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t (original)
+++ rtir/branches/2.3-EXPERIMENTAL/t/constituency/propagation-inherit.t Fri Dec 21 09:16:12 2007
@@ -9,7 +9,7 @@
# XXX: we should use new RT::Test features and start server with
# option we want.
if ( RT->Config->Get('_RTIR_Constituency_Propagation') eq 'inherit' ) {
- plan tests => 152;
+ plan tests => 196;
} else {
plan skip_all => 'constituency propagation algorithm is not "inherit"';
}
@@ -227,3 +227,56 @@
}
}
+diag "check that constituency propagates from a child to a parent after 'Edit', and back"
+ if $ENV{'TEST_VERBOSE'};
+{
+ # can not test this for blocks as those require incident on create
+ foreach my $queue( 'Incident Reports', 'Investigations' ) {
+ diag "create an incident for linking" if $ENV{'TEST_VERBOSE'};
+
+ my $incident_id = create_rtir_ticket_ok(
+ $agent, 'Incidents', { Subject => "test" }, { Constituency => 'EDUNET' },
+ );
+ diag "create a ticket in the '$queue' queue" if $ENV{'TEST_VERBOSE'};
+ my $child_id = create_rtir_ticket_ok(
+ $agent, $queue,
+ { Subject => "test constituency" },
+ { Constituency => 'GOVNET' },
+ );
+ DBIx::SearchBuilder::Record::Cachable::FlushCache();
+
+ diag "check that both have the same correct constituency" if $ENV{'TEST_VERBOSE'};
+ {
+ my $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $incident_id );
+ ok $ticket->id, 'loaded ticket';
+ is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+ 'EDUNET', 'correct value';
+ } {
+ my $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $child_id );
+ ok $ticket->id, 'loaded ticket';
+ is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+ 'GOVNET', 'correct value';
+ }
+
+ diag "link the child to parent" if $ENV{'TEST_VERBOSE'};
+ LinkChildToIncident( $agent, $child_id, $incident_id );
+
+ diag "check that constituency propagates from parent to child on linking" if $ENV{'TEST_VERBOSE'};
+ {
+ my $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $child_id );
+ ok $ticket->id, 'loaded ticket';
+ is uc $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+ 'EDUNET', "child's constituency has been changed";
+ } {
+ my $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $incident_id );
+ ok $ticket->id, 'loaded ticket';
+ is $ticket->FirstCustomFieldValue('_RTIR_Constituency'),
+ 'EDUNET', 'correct value';
+ }
+ }
+}
+
More information about the Rt-commit
mailing list