[Rt-commit] rt branch, 4.0/canonicalize-uris-in-ticketsql, created. rt-4.0.6-250-g5075951
Thomas Sibley
trs at bestpractical.com
Fri Aug 3 17:54:30 EDT 2012
The branch, 4.0/canonicalize-uris-in-ticketsql has been created
at 5075951855fe6bfb4f3698386a1a3d4827f25259 (commit)
- Log -----------------------------------------------------------------
commit 5075951855fe6bfb4f3698386a1a3d4827f25259
Author: Thomas Sibley <trs at bestpractical.com>
Date: Fri Aug 3 14:42:16 2012 -0700
Canonicalize URIs in TicketSQL link limits
The primary improvement is noticeable when searching for tickets with
links to articles:
RefersTo = 'a:42'
now works. Previously the full URI form was required:
RefersTo = 'fsck.com-article://example.com/article/42'
which is not terribly friendly and not (intentionally) exposed anywhere
else.
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 7946399..6dd23e0 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -431,6 +431,10 @@ sub _LinkLimit {
my $is_null = 0;
$is_null = 1 if !$value || $value =~ /^null$/io;
+ unless ($is_null) {
+ $value = RT::URI->new( $sb->CurrentUser )->CanonicalizeURI( $value );
+ }
+
my $direction = $meta->[1] || '';
my ($matchfield, $linkfield) = ('', '');
if ( $direction eq 'To' ) {
diff --git a/lib/RT/URI.pm b/lib/RT/URI.pm
index fce0459..284a75e 100644
--- a/lib/RT/URI.pm
+++ b/lib/RT/URI.pm
@@ -91,7 +91,26 @@ sub new {
return ($self);
}
+=head2 CanonicalizeURI <URI>
+Returns the canonical form of the given URI by calling L</FromURI> and then L</URI>.
+
+If the URI is unparseable by FromURI the passed in URI is simply returned untouched.
+
+=cut
+
+sub CanonicalizeURI {
+ my $self = shift;
+ my $uri = shift;
+ if ($self->FromURI($uri)) {
+ my $canonical = $self->URI;
+ if ($canonical and $uri ne $canonical) {
+ RT->Logger->debug("Canonicalizing URI '$uri' to '$canonical'");
+ $uri = $canonical;
+ }
+ }
+ return $uri;
+}
=head2 FromObject <Object>
diff --git a/t/articles/uri-a.t b/t/articles/uri-a.t
index 82d0f1b..5c1fdaf 100644
--- a/t/articles/uri-a.t
+++ b/t/articles/uri-a.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::Test tests => 7;
+use RT::Test tests => 15;
use_ok("RT::URI::a");
my $uri = RT::URI::a->new($RT::SystemUser);
@@ -26,3 +26,39 @@ is(ref($uri->Object), "RT::Article", "Object loaded is an article");
is($uri->Object->Id, $article->Id, "Object loaded has correct ID");
is($article->URI, 'fsck.com-article://example.com/article/'.$article->Id,
"URI object has correct URI string");
+
+{
+ my $aid = $article->id;
+ my $ticket = RT::Ticket->new( RT->SystemUser );
+ my ($id, $msg) = $ticket->Create(
+ Queue => 1,
+ Subject => 'test ticket',
+ );
+ ok $id, "Created a test ticket";
+
+ # Try searching
+ my $tickets = RT::Tickets->new( RT->SystemUser );
+ $tickets->FromSQL(" RefersTo = 'a:$aid' ");
+ is $tickets->Count, 0, "No results yet";
+
+ # try with the full uri
+ $tickets->FromSQL(" RefersTo = '@{[ $article->URI ]}' ");
+ is $tickets->Count, 0, "Still no results";
+
+ # add the link
+ $ticket->AddLink( Type => 'RefersTo', Target => "a:$aid" );
+
+ # verify the ticket has it
+ my @links = @{$ticket->RefersTo->ItemsArrayRef};
+ is scalar @links, 1, "Has one RefersTo link";
+ is ref $links[0]->TargetObj, "RT::Article", "Link points to an article";
+ is $links[0]->TargetObj->id, $aid, "Link points to the article we specified";
+
+ # search again
+ $tickets->FromSQL(" RefersTo = 'a:$aid' ");
+ is $tickets->Count, 1, "Found one ticket with short URI";
+
+ # search with the full uri
+ $tickets->FromSQL(" RefersTo = '@{[ $article->URI ]}' ");
+ is $tickets->Count, 1, "Found one ticket with full URI";
+}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list