[Rt-commit] rt branch 5.0/menu-search-autocomplete created. rt-5.0.3-29-g701ae00db9

BPS Git Server git at git.bestpractical.com
Tue Jul 26 16:05:29 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/menu-search-autocomplete has been created
        at  701ae00db9ba2778113e60d1637a75c97c4ce9e5 (commit)

- Log -----------------------------------------------------------------
commit 701ae00db9ba2778113e60d1637a75c97c4ce9e5
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jul 26 23:44:53 2022 +0800

    Test article menu searches

diff --git a/t/articles/search-interface.t b/t/articles/search-interface.t
index 1d9d46ea47..68e1aedb56 100644
--- a/t/articles/search-interface.t
+++ b/t/articles/search-interface.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => undef;
+use RT::Test tests => undef, config => 'Set($SelfServiceShowArticleSearch, 1);';
 
 use RT::CustomField;
 use RT::Queue;
@@ -143,6 +143,83 @@ TODO:{
     $m->text_contains('hoi polloi 4');
 }
 
+diag 'menu search';
+$m->submit_form_ok(
+    {
+        form_number => 1,
+        fields  => { q => 'article' },
+    },
+    'search article from menu'
+);
+for my $id ( 1 .. 4 ) {
+    $m->follow_link_ok( { text => $id, url_regex => qr!/Articles/Article/Display\.html! } );
+    $m->text_contains("article $$");
+    $m->back;
+}
+
+$m->submit_form_ok(
+    {
+        form_number => 1,
+        fields  => { q => 'article-not-exist' },
+    },
+    'search article from menu'
+);
+$m->text_contains('No articles matching search criteria found.');
+
+$m->submit_form_ok(
+    {
+        form_number => 1,
+        fields    => { q => 2 },
+    },
+    'search article id from menu'
+);
+is( $m->uri, $url . '/Articles/Article/Display.html?id=2', 'redirect to article display page' );
+
+diag 'selfservice menu search';
+
+my $alice = RT::Test->load_or_create_user(
+    Name         => 'alice',
+    Password     => 'password',
+    EmailAddress => 'alice at example.com',
+    Privileged   => 0,
+);
+ok( $alice && $alice->id, 'loaded or created user' );
+ok( !$alice->Privileged,   'user is not privileged' );
+
+ok( RT::Test->add_rights( { Principal => 'Unprivileged', Right => [qw(ShowArticle)] } ) );
+ok( $m->login( 'alice', 'password', logout => 1 ), 'logged in as an unprivileged user' );
+$m->submit_form_ok(
+    {
+        form_id => 'ArticleSearch',
+        fields  => { q => 'article' },
+    },
+    'search article from selfservice menu'
+);
+
+for my $id ( 1 .. 4 ) {
+    $m->follow_link_ok( { text => $id, url_regex => qr!/SelfService/Article/Display\.html! } );
+    $m->text_contains("article $$");
+    $m->back;
+}
+
+$m->submit_form_ok(
+    {
+        form_id => 'ArticleSearch',
+        fields  => { q => 'article-not-exist' },
+    },
+    'search article from selfservice menu'
+);
+$m->text_contains('No articles matching search criteria found.');
+
+$m->submit_form_ok(
+    {
+        form_id => 'ArticleSearch',
+        fields    => { q => 2 },
+    },
+    'search article id from selfservice menu'
+);
+is( $m->uri, $url . '/SelfService/Article/Display.html?id=2', 'redirect to article display page' );
+
 done_testing;
 
 # When you send $m to this sub, it must be on a page with

commit 200a3e3fa4e8c91d5e94e396bd16da42724263fb
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jul 26 05:06:35 2022 +0800

    Refactor SelfService article search to be more consistent with privileged page
    
    The main difference of the search result content between privileged and
    unprivileged pages is the latter has fewer columns(only id, name and
    summary).

diff --git a/lib/RT/Articles.pm b/lib/RT/Articles.pm
index 2f6e7da86f..a47631ffc3 100644
--- a/lib/RT/Articles.pm
+++ b/lib/RT/Articles.pm
@@ -546,8 +546,9 @@ sub Search {
     my $order = $args{Order};
     if ( $args{'q'} ) {
         $self->SimpleSearch(
-            Term => $args{'q'},
-            Max  => undef,
+            Return => 'Name',
+            Term   => $args{'q'},
+            Max    => undef,
         );
     }
 
diff --git a/share/html/SelfService/Article/Search.html b/share/html/SelfService/Article/Search.html
index 4083270efd..31e9d1d6ba 100644
--- a/share/html/SelfService/Article/Search.html
+++ b/share/html/SelfService/Article/Search.html
@@ -53,7 +53,7 @@
       <&|/l&>Search for Articles matching</&>
     </span>
     <div class="value col-auto">
-      <input class="form-control" type="text" size=20 name="Articles_Content" data-autocomplete="Articles" data-autocomplete-return="id" data-autocomplete-autosubmit="1" />
+      <input class="form-control" type="text" size=20 name="q" value="<% $q // '' %>" data-autocomplete="Articles" data-autocomplete-return="id" data-autocomplete-autosubmit="1" />
     </div>
     <div class="col-auto">
       <input class="form-control btn btn-primary" type="submit" value="<&|/l&>Search</&>">
@@ -61,67 +61,52 @@
   </div>
 </form>
 
-  <div class="form-row">
-    <span class="label col-auto">
-% if ($Articles_Content) {
-%   if ($articles_basics->Count || $articles_content->Count) {
-<&|/l,$Articles_Content&>Articles matching [_1]</&>
+% if ($q) {
+%   if ( $articles->Count ) {
+<& /Elements/CollectionList,
+    Collection => $articles,
+    AllowSorting => 1,
+    OrderBy => \@OrderBy,
+    Order => \@Order,
+    Format => $format,
+    GenericQueryArgs => { %ARGS, Format => $format, },
+    &>
 %   } else {
-<&|/l,$Articles_Content&>No Articles match [_1]</&>
+<p class="description mt-3 ml-3">
+  <&|/l&>No articles matching search criteria found.</&>
+</p>
 %   }
 % }
-    </span>
-  </div>
 
-% my %dedupe_articles;
-% while (my $article = $articles_content->Next) {
-%   $dedupe_articles{$article->Id}++;
-  <div class="form-row">
-    <span class="value col-auto">
-      <a href="Display.html?id=<%$article->Id%>"><%$article->Name || loc('(no name)')%>: <%$article->Summary%></a>
-    </span>
-  </div>
-% }
-
-% while (my $article = $articles_basics->Next) {
-%   next if $dedupe_articles{$article->Id};
-  <div class="form-row">
-    <span class="value col-auto">
-      <a href="Display.html?id=<%$article->Id%>"><%$article->Name || loc('(no name)')%>: <%$article->Summary%></a>
-    </span>
-  </div>
-% }
-</div>
 <%init>
+if ( $ARGS{Articles_Content} ) {
+    RT->Deprecated( Message => 'Passing Articles_Content is deprecated', Instead => 'q', Remove => '5.2' );
+    $q ||= $ARGS{Articles_Content};
+}
 
-if ( $Articles_Content =~ /^(\d+)$/ ) {
+if ( $q =~ /^(\d+)$/ ) {
     RT::Interface::Web::Redirect( RT->Config->Get('WebURL') . 'SelfService/Article/Display.html?id=' . $1 );
 }
 
 use RT::Articles;
 
-my $articles_content = RT::Articles->new( $session{'CurrentUser'} );
-my $articles_basics = RT::Articles->new( $session{'CurrentUser'} );
-if ( $ARGS{'Articles_Content'} ) {
-    $articles_content->LimitCustomField( VALUE => $ARGS{'Articles_Content'},
-                                                OPERATOR => 'LIKE' );
-
-    $articles_basics->Limit( SUBCLAUSE       => 'all',
-                             FIELD           => 'Name',
-                             OPERATOR        => 'LIKE',
-                             VALUE           => $ARGS{'Articles_Content'},
-                             CASESENSITIVE   => 0,
-                             ENTRYAGGREGATOR => "OR" );
-    $articles_basics->Limit( SUBCLAUSE       => 'all',
-                             FIELD           => 'Summary',
-                             OPERATOR        => 'LIKE',
-                             VALUE           => $ARGS{'Articles_Content'},
-                             CASESENSITIVE   => 0,
-                             ENTRYAGGREGATOR => "OR" );
+my $articles = RT::Articles->new( $session{'CurrentUser'} );
+if ( $q ) {
+    $articles->SimpleSearch(
+        Return => 'Name',
+        Term   => $q,
+        Max    => undef,
+    );
 }
 
+my $format = q{
+    '<a href="__WebHomePath__/Article/Display.html?id=__id__">__id__</a>/TITLE:#',
+    '<a href="__WebHomePath__/Article/Display.html?id=__id__">__Name__</a>/TITLE:Name',
+    '__Summary__',};
 
 </%init>
 <%args>
-$Articles_Content => ''
+$q => ''
+ at OrderBy => ()
+ at Order => ()
 </%args>
diff --git a/share/html/SelfService/Elements/SearchArticle b/share/html/SelfService/Elements/SearchArticle
index a3176e28ee..8030807291 100644
--- a/share/html/SelfService/Elements/SearchArticle
+++ b/share/html/SelfService/Elements/SearchArticle
@@ -46,6 +46,6 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <form action="<% RT->Config->Get('WebPath') %>/SelfService/Article/Search.html" id="ArticleSearch">
-<input name="Articles_Content" class="field form-control" placeholder="<&|/l&>Search Articles</&>..." type="search" data-autocomplete="Articles" data-autocomplete-return="id" data-autocomplete-autosubmit="1" />
+<input name="q" class="field form-control" placeholder="<&|/l&>Search Articles</&>..." type="search" data-autocomplete="Articles" data-autocomplete-return="id" data-autocomplete-autosubmit="1" />
 </form>
 

commit 88c6e00090d98b42fd1d23cadde291cd47aaf01a
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jul 26 06:32:17 2022 +0800

    Show no results message for article search page

diff --git a/share/html/Articles/Article/Search.html b/share/html/Articles/Article/Search.html
index 5f0f5c63d7..69ede54400 100644
--- a/share/html/Articles/Article/Search.html
+++ b/share/html/Articles/Article/Search.html
@@ -93,14 +93,22 @@
 </div>
 
 % if ($articles->BuildSelectCountQuery =~ /WHERE/i) {
+
+%   if ( $articles->Count ) {
 <& /Elements/CollectionList,
-    Collection => $articles, 
-    AllowSorting => 1,
-    OrderBy => \@OrderBy,
-    Order => \@Order,
-    Format => $format,
+    Collection           => $articles,
+    AllowSorting     => 1,
+    OrderBy          => \@OrderBy,
+    Order            => \@Order,
+    Format           => $format,
     GenericQueryArgs => { %filtered, Format => $format, },
     &>
+%   } else {
+<p class="description mt-3 ml-3">
+  <&|/l&>No articles matching search criteria found.</&>
+</p>
+%   }
+
 % }
 
 <br />

commit 5d172c5c319d57cc444ee9050f7d76dddbbdf2c7
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jul 26 06:14:51 2022 +0800

    Use SimpleSearch for article searches from top menu
    
    This is to be consistent with autocomplete search. To return the same
    result as before, here we tolerate default search criteria a bit("Name
    LIKE ..." instead of "Name STARTWITH ..."), which is also more practical
    even for autocomplete.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index c6320ac8c5..cc0f36ea62 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2616,7 +2616,7 @@ fields, as well as custom fields, including Content, which are specified as
 =cut
 
 Set($ArticleSearchFields, {
-    Name         => 'STARTSWITH',
+    Name         => 'LIKE',
     Summary      => 'LIKE',
 });
 
diff --git a/lib/RT/Articles.pm b/lib/RT/Articles.pm
index 285cfe6de9..2f6e7da86f 100644
--- a/lib/RT/Articles.pm
+++ b/lib/RT/Articles.pm
@@ -545,21 +545,9 @@ sub Search {
     my $order_by = $args{OrderBy};
     my $order = $args{Order};
     if ( $args{'q'} ) {
-        $self->Limit(
-            FIELD           => 'Name',
-            SUBCLAUSE       => 'NameOrSummary',
-            OPERATOR        => 'LIKE',
-            ENTRYAGGREGATOR => 'OR',
-            CASESENSITIVE   => 0,
-            VALUE           => $args{'q'}
-        );
-        $self->Limit(
-            FIELD           => 'Summary',
-            SUBCLAUSE       => 'NameOrSummary',
-            OPERATOR        => 'LIKE',
-            ENTRYAGGREGATOR => 'OR',
-            CASESENSITIVE   => 0,
-            VALUE           => $args{'q'}
+        $self->SimpleSearch(
+            Term => $args{'q'},
+            Max  => undef,
         );
     }
 

commit 62195b8358628eb4c8024fca2bf6aaf65ecd7897
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jul 26 04:29:23 2022 +0800

    Support article autocomplete in SelfService

diff --git a/share/html/SelfService/Article/Search.html b/share/html/SelfService/Article/Search.html
index b285d9450f..4083270efd 100644
--- a/share/html/SelfService/Article/Search.html
+++ b/share/html/SelfService/Article/Search.html
@@ -53,7 +53,7 @@
       <&|/l&>Search for Articles matching</&>
     </span>
     <div class="value col-auto">
-      <input class="form-control" type="text" size=20 name="Articles_Content" />
+      <input class="form-control" type="text" size=20 name="Articles_Content" data-autocomplete="Articles" data-autocomplete-return="id" data-autocomplete-autosubmit="1" />
     </div>
     <div class="col-auto">
       <input class="form-control btn btn-primary" type="submit" value="<&|/l&>Search</&>">
@@ -93,6 +93,11 @@
 % }
 </div>
 <%init>
+
+if ( $Articles_Content =~ /^(\d+)$/ ) {
+    RT::Interface::Web::Redirect( RT->Config->Get('WebURL') . 'SelfService/Article/Display.html?id=' . $1 );
+}
+
 use RT::Articles;
 
 my $articles_content = RT::Articles->new( $session{'CurrentUser'} );
diff --git a/share/html/SelfService/Elements/SearchArticle b/share/html/SelfService/Elements/SearchArticle
index 1d1802ce73..a3176e28ee 100644
--- a/share/html/SelfService/Elements/SearchArticle
+++ b/share/html/SelfService/Elements/SearchArticle
@@ -46,6 +46,6 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <form action="<% RT->Config->Get('WebPath') %>/SelfService/Article/Search.html" id="ArticleSearch">
-<input name="Articles_Content" class="field form-control" placeholder="<&|/l&>Search Articles</&>..." type="search" />
+<input name="Articles_Content" class="field form-control" placeholder="<&|/l&>Search Articles</&>..." type="search" data-autocomplete="Articles" data-autocomplete-return="id" data-autocomplete-autosubmit="1" />
 </form>
 
diff --git a/share/html/SelfService/Elements/SearchArticle b/share/html/SelfService/Helpers/Autocomplete/Articles
similarity index 89%
copy from share/html/SelfService/Elements/SearchArticle
copy to share/html/SelfService/Helpers/Autocomplete/Articles
index 1d1802ce73..666db2fc03 100644
--- a/share/html/SelfService/Elements/SearchArticle
+++ b/share/html/SelfService/Helpers/Autocomplete/Articles
@@ -45,7 +45,4 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<form action="<% RT->Config->Get('WebPath') %>/SelfService/Article/Search.html" id="ArticleSearch">
-<input name="Articles_Content" class="field form-control" placeholder="<&|/l&>Search Articles</&>..." type="search" />
-</form>
-
+% $m->comp('/Helpers/Autocomplete/Articles', %ARGS);

commit 0ab389813b50dd240bd3d168e0ffc687e5486e4a
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jul 26 04:32:34 2022 +0800

    Support ticket autocomplete in SelfService

diff --git a/share/html/Helpers/Autocomplete/Tickets b/share/html/Helpers/Autocomplete/Tickets
index a4993cbd56..3494ac8e7d 100644
--- a/share/html/Helpers/Autocomplete/Tickets
+++ b/share/html/Helpers/Autocomplete/Tickets
@@ -66,9 +66,6 @@ $m->abort unless defined $return
 
 my $CurrentUser = $session{'CurrentUser'};
 
-# Require privileged users
-$m->abort unless $CurrentUser->Privileged;
-
 my @excludes;
 
 (my $prev, $term) = $term =~ /^((?:\d+\s+)*)(.*)/;
diff --git a/share/html/SelfService/Elements/GotoTicket b/share/html/SelfService/Elements/GotoTicket
index 5b9ea0f68e..715f1bcf38 100644
--- a/share/html/SelfService/Elements/GotoTicket
+++ b/share/html/SelfService/Elements/GotoTicket
@@ -46,5 +46,5 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <form action="<% RT->Config->Get('WebPath') %>/SelfService/Display.html" method="get" id="GotoTicket" name="GotoTicket">
-<input name="id" class="field form-control" placeholder="<&|/l&>Go to Ticket</&>..." type="search"/>
+<input name="id" class="field form-control" placeholder="<&|/l&>Go to Ticket</&>..." type="search" data-autocomplete="Tickets" data-autocomplete-return="id" data-autocomplete-autosubmit="1" />
 </form>
diff --git a/share/html/SelfService/Elements/GotoTicket b/share/html/SelfService/Helpers/Autocomplete/Tickets
similarity index 89%
copy from share/html/SelfService/Elements/GotoTicket
copy to share/html/SelfService/Helpers/Autocomplete/Tickets
index 5b9ea0f68e..4990bc94e4 100644
--- a/share/html/SelfService/Elements/GotoTicket
+++ b/share/html/SelfService/Helpers/Autocomplete/Tickets
@@ -45,6 +45,4 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<form action="<% RT->Config->Get('WebPath') %>/SelfService/Display.html" method="get" id="GotoTicket" name="GotoTicket">
-<input name="id" class="field form-control" placeholder="<&|/l&>Go to Ticket</&>..." type="search"/>
-</form>
+% $m->comp('/Helpers/Autocomplete/Tickets', %ARGS);

commit 24921607d318c5e43016625bef778390b92d30af
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Apr 8 04:49:38 2022 +0800

    Add autocomplete feature for ticket/article/asset search in top menu
    
    If user clicks one item on autocomplete list, it will redirect to the
    corresponding ticket/article/asset display page.

diff --git a/share/html/Articles/Elements/GotoArticle b/share/html/Articles/Elements/GotoArticle
index d7f1e1c756..f847256ce3 100644
--- a/share/html/Articles/Elements/GotoArticle
+++ b/share/html/Articles/Elements/GotoArticle
@@ -47,7 +47,7 @@
 %# END BPS TAGGED BLOCK }}}
 <form action="<% RT->Config->Get('WebPath') %>/Articles/Article/Search.html" class="article-search">
   <input type="hidden" name="HideOptions" value="1" />
-  <input name="q" accesskey="0" class="field form-control" placeholder="<&|/l&>Search Articles</&>..." type="search" results="5" autosave="search-articles" />
+  <input name="q" accesskey="0" class="field form-control" placeholder="<&|/l&>Search Articles</&>..." type="search" results="5" autosave="search-articles"  data-autocomplete="Articles" data-autocomplete-return="id" data-autocomplete-autosubmit="1" />
 % if ($class or $topic) {
 <input type="hidden" name="ExpandTopics" value="1" />
 <select name="Topics">
diff --git a/share/html/Asset/Elements/Search b/share/html/Asset/Elements/Search
index 14ec8005cd..3799405bd3 100644
--- a/share/html/Asset/Elements/Search
+++ b/share/html/Asset/Elements/Search
@@ -46,7 +46,7 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <form action="<% RT->Config->Get('WebPath') %>/Asset/Search/" class="asset-search">
-  <input name="q" accesskey="0" class="field form-control" value="<% $value %>" placeholder="<&|/l&>Search Assets</&>..." type="search" results="5" autosave="search-assets" />
+  <input name="q" accesskey="0" class="field form-control" value="<% $value %>" placeholder="<&|/l&>Search Assets</&>..." type="search" results="5" autosave="search-assets"  data-autocomplete="Assets" data-autocomplete-return="id" data-autocomplete-autosubmit="1" />
 </form>
 <%init>
 my $value = defined $DECODED_ARGS->{q} ? $DECODED_ARGS->{q} : '';
diff --git a/share/html/Elements/SimpleSearch b/share/html/Elements/SimpleSearch
index 8de1d1be37..ce5ebe63da 100644
--- a/share/html/Elements/SimpleSearch
+++ b/share/html/Elements/SimpleSearch
@@ -46,7 +46,7 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <form action="<% RT->Config->Get('WebPath') %><% $SendTo %>" id="simple-search">
-  <input name="q" accesskey="0" class="field form-control" value="<% $value %>" placeholder="<% $Placeholder %>..." type="search" results=5 autosave="simple-search" />
+  <input name="q" accesskey="0" class="field form-control" value="<% $value %>" placeholder="<% $Placeholder %>..." type="search" results=5 autosave="simple-search" data-autocomplete="Tickets" data-autocomplete-return="id" data-autocomplete-autosubmit="1" />
 </form>
 <%init>
 my $value = defined $DECODED_ARGS->{q} ? $DECODED_ARGS->{q} : '';

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list