[Rt-commit] rtir branch, 2.9-trunk, updated. 2.6.1rc1-390-g7131a78

Ruslan Zakirov ruz at bestpractical.com
Wed Sep 21 04:30:33 EDT 2011


The branch, 2.9-trunk has been updated
       via  7131a78befe173de596288e7ed3824c9dab76296 (commit)
       via  e260425958884c42fe6fa3a26a4bade5cb9502df (commit)
       via  cfd926979f309625d1da1ee6f1a7ca5c070c3350 (commit)
       via  18c71dee60edc02f243ddf0f148b6d8c8d9f9f4a (commit)
      from  d7d8c896f265981a9bdd6bb357e3fe9ca279cd74 (commit)

Summary of changes:
 TODO.porting_over_RT4                        |    8 +---
 html/Callbacks/RTIR/Elements/Tabs/Privileged |    2 +-
 html/RTIR/Forward.html                       |   20 +++------
 html/RTIR/index.html                         |   54 +++--------------------
 lib/RT/IR.pm                                 |   60 ++++++++++++++++++++++++++
 t/searches/simple.t                          |   27 ++++++++++++
 6 files changed, 105 insertions(+), 66 deletions(-)
 create mode 100644 t/searches/simple.t

- Log -----------------------------------------------------------------
commit 18c71dee60edc02f243ddf0f148b6d8c8d9f9f4a
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Sep 20 01:09:02 2011 +0400

    use EmailInput on forward

diff --git a/TODO.porting_over_RT4 b/TODO.porting_over_RT4
index 72dfe97..f891fa5 100644
--- a/TODO.porting_over_RT4
+++ b/TODO.porting_over_RT4
@@ -23,9 +23,6 @@
 
 * make Submit buttons names consistent with RT's
 
-* html/RTIR/Forward.html still uses plain inputs for addresses
-
 * re-use CSS squishing
 
 * use latest simple search API in html/RTIR/index.html
-
diff --git a/html/RTIR/Forward.html b/html/RTIR/Forward.html
index e3bd83d..b47fb64 100644
--- a/html/RTIR/Forward.html
+++ b/html/RTIR/Forward.html
@@ -14,20 +14,14 @@
   <td class="value"><% $TicketObj->Subject %></td>
 </tr>
 
-<tr class="to">
-  <td class="label"><&|/l&>To</&>:</td>
-  <td class="value"><input type="text" name="To" size="60" value="<% $ARGS{'To'} %>" /></td>
-</tr>
-
-<tr class="cc">
-  <td class="label"><&|/l&>Cc</&>:</td>
-  <td class="value"><input type="text" name="Cc" size="60" value="<% $ARGS{'Cc'} %>" /></td>
-</tr>
-
-<tr class="bcc">
-  <td class="label"><&|/l&>BCc</&>:</td>
-  <td class="value"><input type="text" name="Bcc" size="60" value="<% $ARGS{'Bcc'} %>" /></td>
+% foreach my $field (To Cc Bcc) {
+<tr class="<% lc $field %>">
+  <td class="label"><% loc($field) %>:</td>
+  <td class="value"><& /Elements/EmailInput,
+    Name => $field, Default => $ARGS{ $field }, Size => undef,
+  &></td>
 </tr>
+% }
 
 </table>
 

commit cfd926979f309625d1da1ee6f1a7ca5c070c3350
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Sep 20 01:09:33 2011 +0400

    no idea what meant by this TODO
    
    things look consistent with RT

diff --git a/TODO.porting_over_RT4 b/TODO.porting_over_RT4
index f891fa5..045456a 100644
--- a/TODO.porting_over_RT4
+++ b/TODO.porting_over_RT4
@@ -21,8 +21,6 @@
 
 === CLEANUP && REFACTORING
 
-* make Submit buttons names consistent with RT's
-
 * re-use CSS squishing
 
 * use latest simple search API in html/RTIR/index.html

commit e260425958884c42fe6fa3a26a4bade5cb9502df
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Sep 20 20:46:41 2011 +0400

    add an item into TODO

diff --git a/TODO.porting_over_RT4 b/TODO.porting_over_RT4
index 045456a..6fdfa1f 100644
--- a/TODO.porting_over_RT4
+++ b/TODO.porting_over_RT4
@@ -24,3 +24,6 @@
 * 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.

commit 7131a78befe173de596288e7ed3824c9dab76296
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Sep 21 12:29:25 2011 +0400

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

diff --git a/TODO.porting_over_RT4 b/TODO.porting_over_RT4
index 6fdfa1f..e751c6c 100644
--- a/TODO.porting_over_RT4
+++ b/TODO.porting_over_RT4
@@ -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.
diff --git a/html/Callbacks/RTIR/Elements/Tabs/Privileged b/html/Callbacks/RTIR/Elements/Tabs/Privileged
index 2f34464..9ebef33 100644
--- a/html/Callbacks/RTIR/Elements/Tabs/Privileged
+++ b/html/Callbacks/RTIR/Elements/Tabs/Privileged
@@ -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'
 ) );
diff --git a/html/RTIR/index.html b/html/RTIR/index.html
index 7d52b8c..7660088 100644
--- a/html/RTIR/index.html
+++ b/html/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>
diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index e404535..9e4817a 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -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;
diff --git a/t/searches/simple.t b/t/searches/simple.t
new file mode 100644
index 0000000..0a8c4c7
--- /dev/null
+++ b/t/searches/simple.t
@@ -0,0 +1,27 @@
+#!/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 at 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});
+}

-----------------------------------------------------------------------


More information about the Rt-commit mailing list