[Rt-commit] rt branch, 4.4/cf-sortable-users, created. rt-4.4.1-240-gca3f084

Brian Duggan brian at bestpractical.com
Fri Mar 31 13:18:54 EDT 2017


The branch, 4.4/cf-sortable-users has been created
        at  ca3f0848c45c23bb7b42d72e02bac3562bacaf6e (commit)

- Log -----------------------------------------------------------------
commit ca3f0848c45c23bb7b42d72e02bac3562bacaf6e
Author: Brian C. Duggan <brian at bestpractical.com>
Date:   Fri Mar 31 12:12:04 2017 -0400

    Make user search results sortable by user CFs
    
    An admin can include an RT::User CF in user search results by defining
    $AdminSearchFormat{Users} in RT_SiteConfig.pm, like so:
    
    Set(%AdminSearchFormat,
            Users =>
                ...
                .q{'__CustomField{SomeUserCF}__'},
                ...
    );
    
    But the RT::Users collection did not support ordering search results
    by CFs on RT::User objects.
    
    This change defines the OrderByCols function in Users.pm with an
    implementation that accounts for custom fields. With this change,
    admins can include user CFs in search results by using
    %AdminSearchFormat and sort the results by those CFs by clicking on
    the column header.
    
    Fixes: I#32680

diff --git a/lib/RT/Users.pm b/lib/RT/Users.pm
index c327f4f..ec792fb 100644
--- a/lib/RT/Users.pm
+++ b/lib/RT/Users.pm
@@ -100,6 +100,27 @@ sub _Init {
     return (@result);
 }
 
+sub OrderByCols {
+    my $self = shift;
+    my @res  = ();
+
+    for my $row (@_) {
+        if ($row->{FIELD} =~ /^CustomField\.\{(.*)\}$/) {
+            my $name = $1 || $2;
+            my $cf = RT::CustomField->new( $self->CurrentUser );
+            $cf->LoadByName(
+                Name => $name,
+                ObjectType => 'RT::User',
+            );
+            if ( $cf->id ) {
+                push @res, $self->_OrderByCF( $row, $cf->id, $cf );
+            }
+        } else {
+            push @res, $row;
+        }
+    }
+    return $self->SUPER::OrderByCols( @res );
+}
 
 =head2 PrincipalsAlias
 

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


More information about the rt-commit mailing list