Commit 7131a78b authored by Ruslan Zakirov's avatar Ruslan Zakirov
Browse files

use latest simple search API in /RTIR/index.html

parent e2604259
......@@ -23,7 +23,5 @@
* re-use CSS squishing
* use latest simple search API in html/RTIR/index.html
* stop abusing $session{'tickets'} so we can get working
First, Prev, Next and Last links in RTIR.
......@@ -451,7 +451,7 @@ if ( $session{'CurrentUser'}->HasRight(Right => 'ModifySelf', Object => $RT::Sys
);
}
PageWidgets()->child('simple_search')->title( $m->scomp(
PageWidgets()->child('simple_search')->raw_html( $m->scomp(
'/Elements/SimpleSearch',
SendTo => '/RTIR/index.html'
) );
......
......@@ -37,54 +37,15 @@ unless ( exists $session{'my_rtir_portlets'} ) {
}
my $portlets = $session{'my_rtir_portlets'};
use Regexp::Common qw(RE_net_IPv4);
if ( $ARGS{'q'} ) {
my $query = $ARGS{'q'};
if ( $query =~ m/^\s*(\d+)\s*$/ ) {
return RT::Interface::Web::Redirect(RT->Config->Get('WebURL')."RTIR/Display.html?id=$query");
}
return if $m->callback(
%ARGS,
CallbackName => 'SearchPreFilter',
query => $query,
if ( defined $q && length $q ) {
my $query = RT::IR->ParseSimpleSearch(
Query => $q,
CurrentUser => $session{'CurrentUser'},
);
# Incidents don't have requestors, but children do
if ( $query =~ m/\@/ ) {
my $children = new RT::Tickets($session{'CurrentUser'});
$children->FromSQL( "( Queue = 'Incident Reports' OR
Queue = 'Investigations' OR
Queue = 'Blocks'
) AND Requestor LIKE '$query'"
);
$query = '';
while ( my $child = $children->Next ) {
$query .= " OR " if $query;
$query .= "HasMember = " . $child->Id;
}
$query ||= 'id = 0';
}
elsif ( $query =~ /^\s*($RE{net}{IPv4})\s*$/o && RT::IR->CustomFields('IP') ) {
$query = RT::IR->Query(
Queue => ['Incidents', 'Incident Reports', 'Investigations', 'Blocks'],
And => "'CustomField.{IP}' = '$1'",
);
return $m->comp(
'/RTIR/Search/Results.html',
Query => $query,
);
}
else {
# Any search on queue name or subject will be for new/open tickets only.
$query = RT::IR->ActiveQuery( Queue => 'Incidents', And => "Subject LIKE '$query'" );
}
return $m->comp(
'/RTIR/Search/Results.html',
Queue => 'Incidents',
Query => $query,
return RT::Interface::Web::Redirect(
RT->Config->Get('WebURL') .'RTIR/Search/Results.html?Query='
. $m->interp->apply_escapes( $query, 'u' )
);
}
......@@ -97,4 +58,5 @@ if ( $HomeRefreshInterval ) {
<%ARGS>
@results => ()
$HomeRefreshInterval => undef
$q => undef
</%ARGS>
......@@ -305,6 +305,34 @@ sub Query {
return join ' AND ', map { /\b(?:AND|OR)\b/? "( $_ )" : $_ } @res;
}
use Regexp::Common qw(RE_net_IPv4);
our @SIMPLE_SEARCH_GUESS = (
[ 11 => sub { return "rtirrequestor" if /\@/ } ],
[ 12 => sub {
return "Rtirip" if /^\s*$RE{net}{IPv4}\s*$/o
&& RT::IR->CustomFields('IP')
} ],
);
sub ParseSimpleSearch {
my $self = shift;
my %args = @_;
local @RT::Search::Googleish::GUESS = (
@RT::Search::Googleish::GUESS,
@SIMPLE_SEARCH_GUESS,
);
my $search = RT::Search::Googleish->new(
Argument => $args{'Query'},
TicketsObj => RT::Tickets->new( $args{'CurrentUser'} ),
);
my $res = $search->QueryToSQL;
if ( $res && $res !~ /\bQueue\b/ ) {
$res = "Queue = 'Incidents' AND ($res)";
}
return $res;
}
sub OurQuery {
my $self = shift;
my $query = shift;
......@@ -774,6 +802,38 @@ if ( RT::IR->HasConstituency ) {
};
}
require RT::Search::Googleish;
package RT::Search::Googleish;
sub HandleRtirip {
return 'RTIR IP' => RT::IR->Query(
Queue => ['Incidents', 'Incident Reports', 'Investigations', 'Blocks'],
And => "'CustomField.{IP}' = '$_[1]'",
);
}
sub HandleRtirrequestor {
my $self = shift;
my $value = shift;
my $children = RT::Tickets->new( $self->TicketsObj->CurrentUser );
$children->FromSQL(
"( Queue = 'Incident Reports' OR
Queue = 'Investigations' OR
Queue = 'Blocks'
) AND Requestor LIKE '$value'"
);
my $query = '';
while ( my $child = $children->Next ) {
$query .= " OR " if $query;
$query .= "HasMember = " . $child->Id;
}
$query ||= 'id = 0';
return 'RTIR Requestor' => "Queue = 'Incidents' AND ($query)";
}
package RT::IR;
RT::Base->_ImportOverlays;
1;
#!/usr/bin/perl
use strict;
use warnings;
use RT::IR::Test tests => 20;
RT::Test->started_ok;
my $agent = default_agent();
{
my $ir_id = $agent->create_ir( {
Subject => 'test ir',
Requestors => 'test@example.com',
}, {
IP => '192.168.1.1',
});
my $inc_id = $agent->create_incident_for_ir(
$ir_id, { Subject => 'test inc' },
);
$agent->get_ok( '/RTIR/index.html?q=test%40example.com' );
$agent->content_like(qr{test inc});
$agent->content_unlike(qr{test ir});
$agent->get_ok( '/RTIR/index.html?q=192.168.1.1' );
$agent->content_like(qr{test ir});
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment