[Rt-commit] rt branch, 4.4/order-by-watcher-default-field, created. rt-4.4.4-553-ge17a8d7651

? sunnavy sunnavy at bestpractical.com
Fri Jun 25 16:28:56 EDT 2021


The branch, 4.4/order-by-watcher-default-field has been created
        at  e17a8d7651fa912bff80efd878bc3c785c44fa35 (commit)

- Log -----------------------------------------------------------------
commit 77bfab0a9cdd5494808536b2014bae06bdc06583
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jun 26 03:07:26 2021 +0800

    Use Name as the default watcher field in search results
    
    When we added more watcher fields in 7abb7900e4, we didn't set the
    default sort field. Without this, for search result format like
    "Requestors", clicking its header on search result page would cause SQL
    error like:
    
        ORDER BY main.Requestors ASC  ... no such column: main.Requestors
    
    Before 7abb7900e4, the default field was "EmailAddress", which is not as
    good as "Name", considering by default we show "Name" for privileged
    users. For unprivileged users, we do show "EmailAddress", but usually
    "Name" and "EmailAddress" are the same(if not, "Name" is also shown), so
    "Name" is still fine.

diff --git a/share/html/Elements/ColumnMap b/share/html/Elements/ColumnMap
index 50082ef37d..84d3a85032 100644
--- a/share/html/Elements/ColumnMap
+++ b/share/html/Elements/ColumnMap
@@ -240,7 +240,15 @@ $WCOLUMN_MAP = $COLUMN_MAP = {
         },
     },
     CustomRole => {
-        attribute => sub { return shift @_ },
+        attribute => sub {
+            my $field = $_[0];
+            if ( $field =~ /^CustomRole\.\{.+\}\.\w+/ ) {
+                return $field;
+            }
+            else {
+                return "$field.Name";
+            }
+        },
         title     => sub {
             my $field = pop @_;
             if (   $field =~ /^\{(.+)\}\.CustomField\.\{(.+)\}/
@@ -339,7 +347,15 @@ if ($RecordClass->DOES("RT::Record::Role::Roles")) {
         for my $role ($RecordClass->Roles(UserDefined => 0)) {
             my $attrs = $RecordClass->Role($role);
             $ROLE_MAP->{$RecordClass}{$role} = {
-                attribute => sub { return shift @_ },
+                attribute => sub {
+                    my $field = $_[0];
+                    if ( $field =~ /\.\w+/ ) {
+                        return $field;
+                    }
+                    else {
+                        return "$field.Name";
+                    }
+                },
                 title => sub {
                     my $field = pop @_;
                     if (   $field =~ /^CustomField\.\{(.+)\}/

commit e17a8d7651fa912bff80efd878bc3c785c44fa35
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jun 26 04:26:35 2021 +0800

    Test order by behavior of "Requestors" header in search results

diff --git a/t/web/search_results.t b/t/web/search_results.t
new file mode 100644
index 0000000000..52db4aff17
--- /dev/null
+++ b/t/web/search_results.t
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+
+RT::Test->create_tickets(
+    {   Queue   => 'General',
+        Subject => 'Requestor order test',
+        Content => 'test',
+    },
+    { Requestor => 'alice at localhost', },
+    { Requestor => 'richard at localhost', },
+    { Requestor => 'bob at localhost', },
+);
+
+ok $m->login, 'logged in';
+
+$m->get_ok('/Search/Results.html?Query=id>0');
+$m->follow_link_ok( { text => 'Requestor' } );
+$m->text_like( qr/alice.*bob.*richard/i, 'Order by Requestors ASC' );
+$m->follow_link_ok( { text => 'Requestor' } );
+$m->text_like( qr/richard.*bob.*alice/i, , 'Order by Requestors DESC' );
+
+done_testing;

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


More information about the rt-commit mailing list