[Rt-commit] rt branch, 4.2/forbid-circular-dependson-and-memberof, created. rt-4.1.17-171-g044c574
? sunnavy
sunnavy at bestpractical.com
Tue Jul 30 10:18:10 EDT 2013
The branch, 4.2/forbid-circular-dependson-and-memberof has been created
at 044c5742ea9db177577f183e618e2a4a4e5746aa (commit)
- Log -----------------------------------------------------------------
commit f1dcb90c763eb0201c4d6008eadecfb6b8943c20
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Jan 24 20:04:54 2012 +0800
forbid circular relationship of DependsOn and MemberOf
because it's wrong in the logic level.
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index e31a2f6..49fe7fc 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -1357,6 +1357,17 @@ sub _AddLink {
return ( $old_link->id, $self->loc("Link already exists"), 1 );
}
+ if ( $args{'Type'} =~ /^(?:DependsOn|MemberOf)$/ ) {
+
+ my @tickets = $self->_AllLinkedTickets(
+ LinkType => $args{'Type'},
+ Direction => $direction eq 'Target' ? 'Base' : 'Target',
+ );
+ if ( grep { $_->id == ( $direction eq 'Target' ? $args{'Base'} : $args{'Target'} ) } @tickets ) {
+ return ( 0, $self->loc("Refused to add link which would create a circular relationship") );
+ }
+ }
+
# Storing the link in the DB.
my $link = RT::Link->new( $self->CurrentUser );
my ($linkid, $linkmsg) = $link->Create( Target => $args{Target},
commit 044c5742ea9db177577f183e618e2a4a4e5746aa
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Jan 27 09:45:55 2012 +0800
circular links tests
diff --git a/t/ticket/circular_links.t b/t/ticket/circular_links.t
new file mode 100644
index 0000000..b6695fe
--- /dev/null
+++ b/t/ticket/circular_links.t
@@ -0,0 +1,45 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my ( $foo, $bar, $baz ) = RT::Test->create_tickets(
+ { Queue => 'General' },
+ { Subject => 'foo' },
+ { Subject => 'bar' },
+ { Subject => 'baz' }
+);
+
+diag "test circular DependsOn";
+my ( $status, $msg ) = $foo->AddLink( Type => 'DependsOn', Target => $bar->id );
+ok( $status, "foo depends on bar" );
+( $status, $msg ) = $foo->AddLink( Type => 'DependsOn', Base => $bar->id );
+ok( !$status, "foo can't be depended on bar" );
+( $status, $msg ) = $bar->AddLink( Type => 'DependsOn', Target => $foo->id );
+ok( !$status, "bar can't depend on foo back" );
+( $status, $msg ) = $bar->AddLink( Type => 'DependsOn', Target => $baz->id );
+ok( $status, "bar depends on baz" );
+( $status, $msg ) = $baz->AddLink( Type => 'DependsOn', Target => $foo->id );
+ok( !$status, "baz can't depend on foo back" );
+
+
+diag "test circular MemberOf";
+( $status, $msg ) = $foo->AddLink( Type => 'MemberOf', Target => $bar->id );
+ok( $status, "foo is a member of bar" );
+( $status, $msg ) = $foo->AddLink( Type => 'MemberOf', Base => $bar->id );
+ok( !$status, "foo can't have member bar" );
+( $status, $msg ) = $bar->AddLink( Type => 'MemberOf', Target => $foo->id );
+ok( !$status, "bar can't be a member of foo" );
+( $status, $msg ) = $bar->AddLink( Type => 'MemberOf', Target => $baz->id );
+ok( $status, "baz is a member of bar" );
+( $status, $msg ) = $baz->AddLink( Type => 'DependsOn', Target => $foo->id );
+ok( !$status, "baz can't be a member of foo" );
+
+
+diag "test circular RefersTo";
+( $status, $msg ) = $foo->AddLink( Type => 'RefersTo', Target => $bar->id );
+ok( $status, "foo refers to bar" );
+( $status, $msg ) = $foo->AddLink( Type => 'RefersTo', Base => $bar->id );
+ok( $status, "foo can be referred to by bar" );
+
+done_testing;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list