[Rt-commit] r4191 - in rt/branches/CHALDEA-EXPERIMENTAL: . etc
lib/RT lib/t/regression
jesse at bestpractical.com
jesse at bestpractical.com
Wed Nov 30 16:29:57 EST 2005
Author: jesse
Date: Wed Nov 30 16:29:56 2005
New Revision: 4191
Added:
rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/14linking.t
Modified:
rt/branches/CHALDEA-EXPERIMENTAL/ (props changed)
rt/branches/CHALDEA-EXPERIMENTAL/etc/RT_Config.pm.in
rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm
Log:
r19608 at truegrounds: jesse | 2005-11-30 16:09:07 -0500
r19565 at truegrounds: jesse | 2005-11-30 15:30:00 -0500
r18893 at truegrounds: jesse | 2005-11-14 13:19:52 -0500
RT-Ticket: 7128
RT-Status: resolved
RT-Update: correspond
A big patch from Todd Chapman (with lots of juicy tests) to optionally
create two transactions when you create a link. (Also, this means that we'll
run scrips twice). This is off by default in RT 3.4
Modified: rt/branches/CHALDEA-EXPERIMENTAL/etc/RT_Config.pm.in
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/etc/RT_Config.pm.in (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/etc/RT_Config.pm.in Wed Nov 30 16:29:56 2005
@@ -482,6 +482,11 @@
@ActiveStatus = qw(new open stalled) unless @ActiveStatus;
@InactiveStatus = qw(resolved rejected deleted) unless @InactiveStatus;
+# Backward compatability setting. Add/Delete Link used to record one
+# transaction and run one scrip. Set this value to 0 if you want
+# both link transactions to have a scrip run.
+Set($LinkTransactionsRun1Scrip , 1);
+
# }}}
Modified: rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/Ticket_Overlay.pm Wed Nov 30 16:29:56 2005
@@ -2502,8 +2502,11 @@
$direction='Base';
}
- if ( $val ) {
- my $remote_uri = RT::URI->new( $RT::SystemUser );
+ if ( $args{'Silent'} ) {
+ return ( $val, $Msg );
+ }
+ else {
+ my $remote_uri = RT::URI->new( $self->CurrentUser );
$remote_uri->FromURI( $remote_link );
my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
@@ -2513,6 +2516,17 @@
TimeTaken => 0
);
+ if ( $remote_uri->IsLocal ) {
+
+ my $OtherObj = $remote_uri->Object;
+ my ( $val, $Msg ) = $OtherObj->_NewTransaction(Type => 'DeleteLink',
+ Field => $direction eq 'Target' ? $LINKDIRMAP{$args{'Type'}}->{Base}
+ : $LINKDIRMAP{$args{'Type'}}->{Target},
+ OldValue => $self->URI,
+ ActivateScrips => ! $RT::LinkTransactionsRun1Scrip,
+ TimeTaken => 0 );
+ }
+
return ( $Trans, $Msg );
}
}
@@ -2525,52 +2539,6 @@
Takes a paramhash of Type and one of Base or Target. Adds that link to this ticket.
-=begin testing
-
-my $q1 = RT::Queue->new($RT::SystemUser);
-my ($id,$msg) = $q1->Create(Name => 'LinkTest1');
-ok ($id,$msg);
-my $q2 = RT::Queue->new($RT::SystemUser);
-($id,$msg) = $q2->Create(Name => 'LinkTest2');
-ok ($id,$msg);
-
-my $u1 = RT::User->new($RT::SystemUser);
-($id,$msg) =$u1->Create(Name => 'LinkTestUser');
-
-ok ($id,$msg);
-
-($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'CreateTicket');
-ok ($id,$msg);
-($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'ModifyTicket');
-ok ($id,$msg);
-
-my $tid;
-
-my $creator = RT::CurrentUser->new($u1->id);
-
-my $ticket = RT::Ticket->new( $creator);
-ok($ticket->isa('RT::Ticket'));
-($id,$tid, $msg) = $ticket->Create(Subject => 'Link test 1', Queue => $q1->id);
-ok ($id,$msg);
-
-
-my $ticket2 = RT::Ticket->new($RT::SystemUser);
-($id, $tid, $msg) = $ticket2->Create(Subject => 'Link test 2', Queue => $q2->id);
-ok ($id, $msg);
-
-($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
-ok(!$id,$msg);
-($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q2, Right => 'CreateTicket');
-ok ($id,$msg);
-($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q2, Right => 'ModifyTicket');
-ok ($id,$msg);
-($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
-ok($id,$msg);
-($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => -1);
-ok(!$id,$msg);
-
-=end testing
-
=cut
sub AddLink {
@@ -2658,7 +2626,7 @@
return ( $val, $Msg );
}
else {
- my $remote_uri = RT::URI->new( $RT::SystemUser );
+ my $remote_uri = RT::URI->new( $self->CurrentUser );
$remote_uri->FromURI( $remote_link );
#Write the transaction
@@ -2667,6 +2635,17 @@
Field => $LINKDIRMAP{$args{'Type'}}->{$direction},
NewValue => $remote_uri->URI || $remote_link,
TimeTaken => 0 );
+
+ if ( $remote_uri->IsLocal ) {
+
+ my $OtherObj = $remote_uri->Object;
+ my ( $val, $Msg ) = $OtherObj->_NewTransaction(Type => 'AddLink',
+ Field => $direction eq 'Target' ? $LINKDIRMAP{$args{'Type'}}->{Base}
+ : $LINKDIRMAP{$args{'Type'}}->{Target},
+ NewValue => $self->URI,
+ ActivateScrips => ! $RT::LinkTransactionsRun1Scrip,
+ TimeTaken => 0 );
+ }
return ( $val, $Msg );
}
Added: rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/14linking.t
==============================================================================
--- (empty file)
+++ rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/14linking.t Wed Nov 30 16:29:56 2005
@@ -0,0 +1,143 @@
+use Test::More tests => '39';
+use_ok('RT');
+use_ok('RT::Ticket');
+use_ok('RT::ScripConditions');
+use_ok('RT::ScripActions');
+use_ok('RT::Template');
+use_ok('RT::Scrips');
+use_ok('RT::Scrip');
+RT::LoadConfig();
+RT::Init();
+
+use File::Temp qw/tempfile/;
+my ($fh, $filename) = tempfile( UNLINK => 1, SUFFIX => '.rt');
+my $link_scrips_orig = $RT::LinkTransactionsRun1Scrip;
+$RT::LinkTransactionsRun1Scrip = 1;
+
+my $condition = RT::ScripCondition->new( $RT::SystemUser );
+$condition->Load('User Defined');
+ok($condition->id);
+my $action = RT::ScripAction->new( $RT::SystemUser );
+$action->Load('User Defined');
+ok($action->id);
+my $template = RT::Template->new( $RT::SystemUser );
+$template->Load('Blank');
+ok($template->id);
+
+my $q1 = RT::Queue->new($RT::SystemUser);
+my ($id,$msg) = $q1->Create(Name => "LinkTest1.$$");
+ok ($id,$msg);
+my $q2 = RT::Queue->new($RT::SystemUser);
+($id,$msg) = $q2->Create(Name => "LinkTest2.$$");
+ok ($id,$msg);
+
+my $commit_code = <<END;
+open(FILE, "<$filename");
+my \$data = <FILE>;
+chomp \$data;
+close FILE;
+open(FILE, ">$filename");
+if (\$self->TransactionObj->Type eq 'AddLink') {
+ print FILE \$data+1, "\n";
+}
+else {
+ print FILE \$data-1, "\n";
+}
+close FILE;
+1;
+END
+
+my $Scrips = RT::Scrips->new( $RT::SystemUser );
+$Scrips->UnLimit;
+while ( my $Scrip = $Scrips->Next ) {
+ $Scrip->Delete if $Scrip->Description =~ /Add or Delete Link \d+/;
+}
+
+
+my $scrip = RT::Scrip->new($RT::SystemUser);
+($id,$msg) = $scrip->Create( Description => "Add or Delete Link $$",
+ ScripCondition => $condition->id,
+ ScripAction => $action->id,
+ Template => $template->id,
+ Stage => 'TransactionCreate',
+ Queue => 0,
+ CustomIsApplicableCode => '$self->TransactionObj->Type =~ /(Add|Delete)Link/;',
+ CustomPrepareCode => '1;',
+ CustomCommitCode => $commit_code,
+ );
+ok($id, "Scrip created");
+
+my $u1 = RT::User->new($RT::SystemUser);
+($id,$msg) =$u1->Create(Name => "LinkTestUser.$$");
+
+ok ($id,$msg);
+
+($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'CreateTicket');
+ok ($id,$msg);
+($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q1, Right => 'ModifyTicket');
+ok ($id,$msg);
+
+my $tid;
+
+my $creator = RT::CurrentUser->new($u1->id);
+
+my $ticket = RT::Ticket->new( $creator);
+ok($ticket->isa('RT::Ticket'));
+($id,$tid, $msg) = $ticket->Create(Subject => 'Link test 1', Queue => $q1->id);
+ok ($id,$msg);
+
+
+my $ticket2 = RT::Ticket->new($RT::SystemUser);
+($id, $tid, $msg) = $ticket2->Create(Subject => 'Link test 2', Queue => $q2->id);
+ok ($id, $msg);
+
+($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
+ok(!$id,$msg);
+ok(link_count($filename) == 0, "scrips ok");
+($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q2, Right => 'CreateTicket');
+ok ($id,$msg);
+($id,$msg) = $u1->PrincipalObj->GrantRight ( Object => $q2, Right => 'ModifyTicket');
+ok ($id,$msg);
+($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
+ok($id,$msg);
+ok(link_count($filename) == 1, "scrips ok");
+($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => -1);
+ok(!$id,$msg);
+ok(link_count($filename) == 1, "scrips ok");
+
+my $transactions = $ticket2->Transactions;
+$transactions->Limit( FIELD => 'Type', VALUE => 'AddLink' );
+ok( $transactions->Count == 1, "Transaction found in other ticket" );
+ok( $transactions->First->Field eq 'ReferredToBy');
+ok( $transactions->First->NewValue eq $ticket->URI );
+
+($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id);
+ok($id,$msg);
+ok(link_count($filename) == 0, "scrips ok");
+$transactions = $ticket2->Transactions;
+$transactions->Limit( FIELD => 'Type', VALUE => 'DeleteLink' );
+ok( $transactions->Count == 1, "Transaction found in other ticket" );
+ok( $transactions->First->Field eq 'ReferredToBy');
+ok( $transactions->First->OldValue eq $ticket->URI );
+
+$RT::LinkTransactionsRun1Scrip = 0;
+($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => $ticket2->id);
+ok($id,$msg);
+ok(link_count($filename) == 2, "scrips ok");
+($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id);
+ok($id,$msg);
+ok(link_count($filename) == 0, "scrips ok");
+
+# restore
+$RT::LinkTransactionsRun1Scrip = $link_scrips_orig;
+
+sub link_count {
+
+ my $file = shift;
+ open(FILE, "<$file");
+ my $data = <FILE>;
+ chomp $data;
+ return $data + 0;
+ close FILE;
+
+}
More information about the Rt-commit
mailing list