[Rt-devel] Shouldn't LocalBase and LocalTarget be zero for non-Ticket objects?

Todd Chapman todd at chaka.net
Wed Mar 8 17:12:27 EST 2006


On Wed, Mar 08, 2006 at 02:31:25PM -0500, Jesse Vincent wrote:
> 
> 
> 
> On Wed, Mar 08, 2006 at 02:29:58PM -0500, Todd Chapman wrote:
> > RT::Link->Create only checks if the Base/Target IsLocal
> > before setting LocalBase/LocalTarget. Shouldn't it also
> > make sure that the object ISA RT::Ticket?
> 
> Yes.
> 

Attached patch and additional tests. Bcc to rt-bugs.

All related tests pass. Some 3.5 tests doen't pass but
I think that is expected. Test files that don't pass:

Failed Test                       Stat Wstat Total Fail  Failed  List of Failed
-------------------------------------------------------------------------------
lib/t/regression/12-search.t        11  2816    39   11  28.21%  18-19 21-22
                                                                 32-33 35-39
lib/t/regression/20-sort-by-reque    2   512    55    2   3.64%  54-55



-Todd
-------------- next part --------------
=== lib/RT/Link_Overlay.pm
==================================================================
--- lib/RT/Link_Overlay.pm	(revision 5740)
+++ lib/RT/Link_Overlay.pm	(local)
@@ -141,18 +141,20 @@
 
 
     if ( $base->IsLocal ) {
-        unless (UNIVERSAL::can($base->Object, 'Id')) {
+        my $object = $base->Object;
+        unless (UNIVERSAL::can($object, 'Id')) {
             return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Base'}));
         
         }
-        $base_id = $base->Object->Id;
+        $base_id = $object->Id if UNIVERSAL::isa($object, 'RT::Ticket');
     }
     if ( $target->IsLocal ) {
-        unless (UNIVERSAL::can($target->Object, 'Id')) {
+        my $object = $target->Object;
+        unless (UNIVERSAL::can($object, 'Id')) {
             return (undef, $self->loc("[_1] appears to be a local object, but can't be found in the database", $args{'Target'}));
         
         }
-        $target_id = $target->Object->Id;
+        $target_id = $object->Id if UNIVERSAL::isa($object, 'RT::Ticket');
     }
 
     # {{{ We don't want references to ourself
=== lib/t/regression/14linking.t
==================================================================
--- lib/t/regression/14linking.t	(revision 5740)
+++ lib/t/regression/14linking.t	(local)
@@ -1,4 +1,4 @@
-use Test::More  tests => '39';
+use Test::More  tests => '52';
 use_ok('RT');
 use_ok('RT::Ticket');
 use_ok('RT::ScripConditions');
@@ -6,9 +6,12 @@
 use_ok('RT::Template');
 use_ok('RT::Scrips');
 use_ok('RT::Scrip');
+use_ok('RT::Link');
 RT::LoadConfig();
 RT::Init();
 
+use strict;
+
 use File::Temp qw/tempfile/;
 my ($fh, $filename) = tempfile( UNLINK => 1, SUFFIX => '.rt');
 my $link_scrips_orig = $RT::LinkTransactionsRun1Scrip;
@@ -131,6 +134,65 @@
 # restore
 $RT::LinkTransactionsRun1Scrip = $link_scrips_orig;
 
+my $link = RT::Link->new( $RT::SystemUser );
+($id,$msg) = $link->Create( Base => $ticket->URI, Target => $ticket2->URI, Type => 'MyLinkType' );
+ok($id, $msg);
+ok($link->LocalBase   == $ticket->id,  "LocalBase   set correctly");
+ok($link->LocalTarget == $ticket2->id, "LocalTarget set correctly");
+
+*RT::NotTicket::Id = sub { return $$ };
+*RT::NotTicket::id = &RT::NotTicket::Id;
+
+{
+    package RT::URI::not_ticket;
+    use RT::URI::base;
+    use vars qw(@ISA);
+    @ISA = qw/RT::URI::base/;
+    sub IsLocal { 1; }
+    sub Object { return bless {}, 'RT::NotTicket'; }
+}
+
+my $orig_getresolver = \&RT::URI::_GetResolver;
+
+    *RT::URI::_GetResolver = sub {
+        my $self = shift;
+        my $scheme = shift;
+
+        $scheme =~ s/(\.|-)/_/g;
+        my $resolver;
+        my $module = "RT::URI::$scheme";
+        $resolver = $module->new($self->CurrentUser);
+
+       if ($resolver) {
+           $self->{'resolver'} = $resolver;
+        } else {
+            $self->{'resolver'} = RT::URI::base->new($self->CurrentUser);
+        }
+    };
+
+($id,$msg) = $link->Create( Base => "not_ticket::$RT::Organization/notticket/$$", Target => $ticket2->URI, Type => 'MyLinkType' );
+ok($id, $msg);
+ok($link->LocalBase   == 0,            "LocalBase set correctly");
+ok($link->LocalTarget == $ticket2->id, "LocalTarget set correctly");
+
+($id,$msg) = $link->Create( Target => "not_ticket::$RT::Organization/notticket/$$", Base => $ticket->URI, Type => 'MyLinkType' );
+ok($id, $msg);
+ok($link->LocalTarget == 0,           "LocalTarget set correctly");
+ok($link->LocalBase   == $ticket->id, "LocalBase set correctly");
+
+($id,$msg) = $link->Create(
+                       Target => "not_ticket::$RT::Organization/notticket/1$$",
+                       Base   => "not_ticket::$RT::Organization/notticket/$$",
+                       Type => 'MyLinkType' );
+
+ok($id, $msg);
+ok($link->LocalTarget == 0, "LocalTarget set correctly");
+ok($link->LocalBase   == 0, "LocalBase set correctly");
+
+# restore _GetResolver
+*RT::URI::_GetResolver = $orig_getresolver;
+
+
 sub link_count {
 
     my $file = shift;


More information about the Rt-devel mailing list