[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.7-330-g3bc23af
Ruslan Zakirov
ruz at bestpractical.com
Mon Apr 5 09:07:21 EDT 2010
The branch, 3.8-trunk has been updated
via 3bc23af0bdc4394d457b58a790eb22fdf31a9a7e (commit)
via f94b385b394a561e3382330d35d82afd43c578c3 (commit)
from 0dbbe8a30c96c518d80e80ad23625ea56950fb2d (commit)
Summary of changes:
etc/RT_Config.pm.in | 22 ----
lib/RT/Search/Googleish.pm | 229 ++++++++++++++--------------------------
share/html/Search/Results.html | 6 -
t/api/emailparser.t | 17 +---
t/web/googleish_search.t | 136 ------------------------
5 files changed, 82 insertions(+), 328 deletions(-)
delete mode 100644 t/web/googleish_search.t
- Log -----------------------------------------------------------------
commit f94b385b394a561e3382330d35d82afd43c578c3
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sat Apr 3 01:01:10 2010 +0400
RTAddressRegexp is not defined these days
diff --git a/t/api/emailparser.t b/t/api/emailparser.t
index 4807138..940c26f 100644
--- a/t/api/emailparser.t
+++ b/t/api/emailparser.t
@@ -1,32 +1,19 @@
use strict;
use warnings;
-use RT;
+
use RT::Test tests => 4;
+RT->Config->Set( RTAddressRegexp => qr/^rt\@example.com$/i );
-{
ok(require RT::EmailParser);
-
-}
-
-{
-
is(RT::EmailParser::IsRTAddress("","rt\@example.com"),1, "Regexp matched rt address" );
is(RT::EmailParser::IsRTAddress("","frt\@example.com"),undef, "Regexp didn't match non-rt address" );
-
-}
-
-{
-
my @before = ("rt\@example.com", "frt\@example.com");
my @after = ("frt\@example.com");
ok(eq_array(RT::EmailParser::CullRTAddresses("", at before), at after), "CullRTAddresses only culls RT addresses");
-
-}
-
1;
commit 3bc23af0bdc4394d457b58a790eb22fdf31a9a7e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Mon Apr 5 16:45:58 2010 +0400
Revert "Merge remote branch 'origin/googleish-refactor' into 3.8-trunk"
This reverts commit 979eb8c6140ae04becefcaadf32356a63ea1172e, reversing
changes made to a9f1393c344a8e8f10ead7fd59e0041b5f44acee.
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 5384493..3f415fc 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1522,28 +1522,6 @@ Set($DefaultTimeUnitsToHours, 0);
=back
-=item C<$SearchResultsAutoRedirect>
-
-when only one ticket is found in search, use this to redirect to the ticket
-display page automatically.
-
-=cut
-
-Set($SearchResultsAutoRedirect, 0);
-
-=back
-
-=item C<$OnlySearchActiveTicketsInSimpleSearch>
-
-When query in simple search doesn't have status info,
-use this to only search active ones.
-
-=cut
-
-Set($OnlySearchActiveTicketsInSimpleSearch, 1);
-
-=back
-
=head1 L<Net::Server> (rt-server) Configuration
=over 4
diff --git a/lib/RT/Search/Googleish.pm b/lib/RT/Search/Googleish.pm
index ed28f70..4c14c47 100644
--- a/lib/RT/Search/Googleish.pm
+++ b/lib/RT/Search/Googleish.pm
@@ -96,179 +96,110 @@ sub QueryToSQL {
my $query = shift || $self->Argument;
my @keywords = grep length, map { s/^\s+//; s/\s+$//; $_ }
- split /((?:fulltext:)?$re_delim|\s+)/o, $query;
-
- my (@keyvalue_clauses, @status_clauses, @other_clauses);
-
- for my $keyword (@keywords) {
- my @clauses;
- if ( ( @clauses = $self->TranslateCustom($keyword) ) ||
- ( @clauses = $self->TranslateKeyValue($keyword) ) ) {
- push @keyvalue_clauses, @clauses;
- next;
- } elsif ( @clauses = $self->TranslateStatus($keyword) ) {
- push @status_clauses, @clauses;
- next;
+ split /((?:fulltext:)?$re_delim|\s+)/o, $query;
+
+ my (
+ @tql_clauses, @owner_clauses, @queue_clauses,
+ @user_clauses, @id_clauses, @status_clauses
+ );
+ my ( $Queue, $User );
+ for my $key (@keywords) {
+
+ # Is this a ticket number? If so, go to it.
+ # But look into subject as well
+ if ( $key =~ m/^\d+$/ ) {
+ push @id_clauses, "id = '$key'", "Subject LIKE '$key'";
}
- for my $action (qw/Number User Queue Owner Others/) {
- my $translate = 'Translate' . $action;
- if ( my @clauses = $self->$translate($keyword) ) {
- push @other_clauses, @clauses;
- next;
+ # if it's quoted string then search it "as is" in subject or fulltext
+ elsif ( $key =~ /^(fulltext:)?($re_delim)$/io ) {
+ if ( $1 ) {
+ push @tql_clauses, "Content LIKE $2";
+ } else {
+ push @tql_clauses, "Subject LIKE $2";
}
}
- }
- push @other_clauses, $self->ProcessExtraQueues;
- unless (@status_clauses) {
- push @status_clauses, $self->ProcessExtraStatus;
- }
+ elsif ( $key =~ /^fulltext:(.*?)$/i ) {
+ $key = $1;
+ $key =~ s/['\\].*//g;
+ push @tql_clauses, "Content LIKE '$key'";
- my @tql_clauses = join( " AND ", sort @keyvalue_clauses ); # Yes, AND!
- push @tql_clauses, join( " OR ", sort @status_clauses );
- push @tql_clauses, join( " OR ", sort @other_clauses );
- @tql_clauses = grep { $_ ? $_ = "( $_ )" : undef } @tql_clauses;
- return join " AND ", sort @tql_clauses;
-}
-
-# }}}
-
-# {{{ sub Prepare
-sub Prepare {
- my $self = shift;
- my $tql = $self->QueryToSQL( $self->Argument );
-
- $RT::Logger->debug($tql);
-
- $self->TicketsObj->FromSQL($tql);
- return (1);
-}
-
-# }}}
+ }
-sub TranslateKeyValue {
- my $self = shift;
- my $key = shift;
+ elsif ( $key =~ /\w+\@\w+/ ) {
+ push @user_clauses, "Requestor LIKE '$key'";
+ }
- if ( $key =~ /(subject|cf\.(?:[^:]*?)|content|requestor|id|status|owner|queue|fulltext):(['"]?)(.+)\2/i )
- {
- my $field = $1;
- my $value = $3;
- $value =~ s/(['"])/\\$1/g;
+ # Is there a status with this name?
+ elsif (
+ $Queue = RT::Queue->new( $self->TicketsObj->CurrentUser )
+ and $Queue->IsValidStatus($key)
+ )
+ {
+ push @status_clauses, "Status = '" . $key . "'";
+ }
- if ( $field =~ /id|status|owner|queue/i ) {
- return "$field = '$value'";
+ # Is there a queue named $key?
+ elsif ( $Queue = RT::Queue->new( $self->TicketsObj->CurrentUser )
+ and $Queue->Load($key)
+ and $Queue->id )
+ {
+ my $quoted_queue = $Queue->Name;
+ $quoted_queue =~ s/'/\\'/g;
+ push @queue_clauses, "Queue = '$quoted_queue'";
}
- elsif ( $field =~ /fulltext/i ) {
- return "Content LIKE '$value'";
+
+ # Is there a owner named $key?
+ elsif ( $User = RT::User->new( $self->TicketsObj->CurrentUser )
+ and $User->Load($key)
+ and $User->id
+ and $User->Privileged )
+ {
+ push @owner_clauses, "Owner = '" . $User->Name . "'";
}
+
+ # Else, subject must contain $key
else {
- return "$field LIKE '$value'";
+ $key =~ s/['\\].*//g;
+ push @tql_clauses, "Subject LIKE '$key'";
}
}
- return;
-}
-
-sub TranslateNumber {
- my $self = shift;
- my $key = shift;
-
- if ( $key =~ /^\d+$/ ) {
- return ("id = '$key'", "Subject LIKE '$key'");
- }
- return;
-}
-
-sub TranslateStatus {
- my $self = shift;
- my $key = shift;
-
- my $Queue = RT::Queue->new( $self->TicketsObj->CurrentUser );
- if ( $Queue->IsValidStatus($key) ) {
- return "Status = '$key'";
- }
- return;
-}
-
-sub TranslateQueue {
- my $self = shift;
- my $key = shift;
-
- my $Queue = RT::Queue->new( $self->TicketsObj->CurrentUser );
- $Queue->Load($key);
- if ( $Queue->id ) {
- my $quoted_queue = $Queue->Name;
- $quoted_queue =~ s/'/\\'/g;
- return "Queue = '$quoted_queue'";
- }
- return;
-}
-
-sub TranslateUser {
- my $self = shift;
- my $key = shift;
-
- if ( $key =~ /\w+\@\w+/ ) {
- $key =~ s/(['"])/\\$1/g;
- return "Requestor LIKE '$key'";
- }
- return;
-}
-
-sub TranslateOwner {
- my $self = shift;
- my $key = shift;
-
- my $User = RT::User->new( $self->TicketsObj->CurrentUser );
- $User->Load($key);
- if ( $User->id && $User->Privileged ) {
- my $name = $User->Name;
- $name =~ s/(['"])/\\$1/g;
- return "Owner = '" . $name . "'";
- }
- return;
-}
-
-sub TranslateOthers {
- my $self = shift;
- my $key = shift;
-
- $key =~ s{^(['"])(.*)\1$}{$2}; # 'foo' => foo
- $key =~ s/(['"])/\\$1/g; # foo'bar => foo\'bar
-
- return "Subject LIKE '$key'";
-}
-
-sub ProcessExtraQueues {
- my $self = shift;
- my %args = @_;
# restrict to any queues requested by the caller
- my @clauses;
- for my $queue ( @{ $self->{'Queues'} } ) {
- my $QueueObj = RT::Queue->new( $self->TicketsObj->CurrentUser );
- next unless $QueueObj->Load($queue);
+ for my $queue (@{ $self->{'Queues'} }) {
+ my $QueueObj = RT::Queue->new($self->TicketsObj->CurrentUser);
+ $QueueObj->Load($queue) or next;
my $quoted_queue = $QueueObj->Name;
$quoted_queue =~ s/'/\\'/g;
- push @clauses, "Queue = '$quoted_queue'";
+ push @queue_clauses, "Queue = '$quoted_queue'";
}
- return @clauses;
-}
-
-sub ProcessExtraStatus {
- my $self = shift;
- if ( RT::Config->Get('OnlySearchActiveTicketsInSimpleSearch',$self->TicketsObj->CurrentUser) ) {
- return join( " OR ", map "Status = '$_'", RT::Queue->ActiveStatusArray() );
+ push @tql_clauses, join( " OR ", sort @id_clauses );
+ push @tql_clauses, join( " OR ", sort @owner_clauses );
+ if ( ! @status_clauses ) {
+ push @tql_clauses, join( " OR ", map "Status = '$_'", RT::Queue->ActiveStatusArray());
+ } else {
+ push @tql_clauses, join( " OR ", sort @status_clauses );
}
- return;
+ push @tql_clauses, join( " OR ", sort @user_clauses );
+ push @tql_clauses, join( " OR ", sort @queue_clauses );
+ @tql_clauses = grep { $_ ? $_ = "( $_ )" : undef } @tql_clauses;
+ return join " AND ", sort @tql_clauses;
}
+# }}}
-sub TranslateCustom {
- my $self = shift;
- return;
+# {{{ sub Prepare
+sub Prepare {
+ my $self = shift;
+ my $tql = $self->QueryToSQL($self->Argument);
+
+ $RT::Logger->debug($tql);
+
+ $self->TicketsObj->FromSQL($tql);
+ return(1);
}
+# }}}
eval "require RT::Search::Googleish_Vendor";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Search/Googleish_Vendor.pm});
diff --git a/share/html/Search/Results.html b/share/html/Search/Results.html
index 92c9f10..22858f1 100755
--- a/share/html/Search/Results.html
+++ b/share/html/Search/Results.html
@@ -186,12 +186,6 @@ my $genpage = sub {
Page => shift(@_),
);
};
-
-if ( RT->Config->Get('SearchResultsAutoRedirect') && $ticketcount == 1 ) {
- RT::Interface::Web::Redirect( RT->Config->Get('WebURL')
- ."Ticket/Display.html?id=". $session{tickets}->First->id );
-}
-
my $BaseURL = RT->Config->Get('WebPath')."/Search/Results.html?";
$link_rel{first} = $BaseURL . $genpage->(1) if $Page > 1;
$link_rel{prev} = $BaseURL . $genpage->($Page - 1) if $Page > 1;
diff --git a/t/web/googleish_search.t b/t/web/googleish_search.t
deleted file mode 100644
index 6afc2f5..0000000
--- a/t/web/googleish_search.t
+++ /dev/null
@@ -1,136 +0,0 @@
-#!/usr/bin/env perl
-use strict;
-use warnings;
-
-use RT::Test tests => 61;
-my ($baseurl, $m) = RT::Test->started_ok;
-my $url = $m->rt_base_url;
-
-my $queue = RT::Queue->new($RT::SystemUser);
-$queue->Create( Name => 'other' );
-ok( $queue->id, 'created queue other');
-
-my $ticket_found_1 = RT::Ticket->new($RT::SystemUser);
-my $ticket_found_2 = RT::Ticket->new($RT::SystemUser);
-my $ticket_not_found = RT::Ticket->new($RT::SystemUser);
-
-$ticket_found_1->Create(
- Subject => 'base ticket 1'.$$,
- Queue => 'general',
- Owner => 'root',
- Requestor => 'customsearch at localhost',
- Content => 'this is base ticket 1',
-);
-ok( $ticket_found_1->id, 'created ticket for custom search');
-
-
-$ticket_found_2->Create(
- Subject => 'base ticket 2'.$$,
- Queue => 'general',
- Owner => 'root',
- Requestor => 'customsearch at localhost',
- Content => 'this is base ticket 2',
-);
-ok( $ticket_found_2->id, 'created ticket for custom search');
-
-$ticket_not_found = RT::Ticket->new($RT::SystemUser);
-$ticket_not_found->Create(
- Subject => 'not found subject' . $$,
- Queue => 'other',
- Owner => 'nobody',
- Requestor => 'notfound at localhost',
- Content => 'this is not found content',
-);
-ok( $ticket_not_found->id, 'created ticket for custom search');
-
-ok($m->login, 'logged in');
-
-my @queries = (
- 'base ticket', 'root',
- 'customsearch at localhost', 'requestor:customsearch',
- 'subject:base', 'subject:"base ticket"',
- 'queue:general', 'owner:root',
-);
-
-for my $q (@queries) {
- $m->form_with_fields('q');
- $m->field( q => $q );
- $m->submit;
- $m->content_contains( 'base ticket 1', 'base ticket 1 is found' );
- $m->content_contains( 'base ticket 2', 'base ticket 2 is found' );
- $m->content_lacks( 'not found subject', 'not found ticket is not found' );
-}
-
-$ticket_not_found->SetStatus('open');
-is( $ticket_not_found->Status, 'open', 'status of not found ticket is open' );
- at queries = qw/new status:new/;
-for my $q (@queries) {
- $m->form_with_fields('q');
- $m->field( q => $q );
- $m->submit;
- $m->content_contains( 'base ticket 1', 'base ticket 1 is found' );
- $m->content_contains( 'base ticket 2', 'base ticket 2 is found' );
- $m->content_lacks( 'not found subject', 'not found ticket is not found' );
-}
-
- at queries = ( 'fulltext:"base ticket 1"', "'base ticket 1'" );
-for my $q (@queries) {
- $m->form_with_fields('q');
- $m->field( q => $q );
- $m->submit;
- $m->content_contains( 'base ticket 1', 'base ticket 1 is found' );
- $m->content_lacks( 'base ticket 2', 'base ticket 2 is not found' );
- $m->content_lacks( 'not found subject', 'not found ticket is not found' );
-}
-
-# now let's test with ' or "
-for my $quote ( q{'}, q{"} ) {
- my $user = RT::User->new($RT::SystemUser);
- is( ref($user), 'RT::User' );
- my ( $id, $msg ) = $user->Create(
- Name => qq!foo${quote}bar!,
- EmailAddress => qq!foo${quote}bar$$\@example.com !,
- Privileged => 1,
- );
- ok ($id, "Creating user - " . $msg );
-
- my ( $grantid, $grantmsg ) =
- $user->PrincipalObj->GrantRight( Right => 'OwnTicket' );
- ok( $grantid, $grantmsg );
-
-
-
- my $ticket_quote = RT::Ticket->new($RT::SystemUser);
- $ticket_quote->Create(
- Subject => qq!base${quote}ticket $$!,
- Queue => 'general',
- Owner => $user->Name,
- Requestor => qq!custom${quote}search\@localhost!,
- Content => qq!this is base${quote}ticket with quote inside!,
- );
- ok( $ticket_quote->id, 'created ticket with quote for custom search' );
-
- @queries = (
- qq!fulltext:base${quote}ticket!,
- "base${quote}ticket",
- "owner:foo${quote}bar",
- "foo${quote}bar",
-
- # email doesn't allow " character
- $quote eq q{'}
- ? (
- "requestor:custom${quote}search\@localhost",
- "custom${quote}search\@localhost",
- )
- : (),
- );
- for my $q (@queries) {
- $m->form_with_fields('q');
- $m->field( q => $q );
- $m->submit;
- my $escape_quote = $quote;
- RT::Interface::Web::EscapeUTF8(\$escape_quote);
- $m->content_contains( "base${escape_quote}ticket",
- "base${quote}ticket is found" );
- }
-}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list