[Rt-commit] rt branch, owner-autocomplete, updated. rt-3.8.8-495-g8e5fc61

Thomas Sibley trs at bestpractical.com
Mon Aug 23 09:56:59 EDT 2010


The branch, owner-autocomplete has been updated
       via  8e5fc618548202cd591bc517c522d31c8221143c (commit)
      from  11fe7223ad743dc2783bc333511fe34fb13754d8 (commit)

Summary of changes:
 etc/RT_Config.pm.in                    |   15 +++++++++++----
 share/html/Helpers/Autocomplete/Owners |   13 ++++++++-----
 share/html/Helpers/Autocomplete/Users  |   13 ++++++++-----
 3 files changed, 27 insertions(+), 14 deletions(-)

- Log -----------------------------------------------------------------
commit 8e5fc618548202cd591bc517c522d31c8221143c
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Aug 23 09:58:15 2010 -0400

    Allow specifying a match operator for user autocomplete fields
    
    This also changes the defaults for EmailAddress and Name to STARTSWITH
    rather than LIKE.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 089924b..ee90902 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1611,17 +1611,24 @@ Set($DefaultTimeUnitsToHours, 0);
 
 =item C<$UserAutocompleteFields>
 
-Specifies which fields of L<RT::User> to match against when autocompleting
-users.  Not all User fields are publically accessible and hence won't work for
+Specifies which fields of L<RT::User> to match against and how to match each
+field when autocompleting users.  Valid match methods are LIKE, STARTSWITH, and
+ENDSWITH.
+
+Not all User fields are publically accessible and hence won't work for
 autocomplete unless you override their accessibility using a local overlay or a
 plugin.  Out of the box the following fields are public: Name, EmailAddress,
 RealName, NickName, and Organization.
 
-Default: C<< Set( $UserAutocompleteFields, [qw(EmailAddress Name RealName)] ) >>
+Default: C<< Set( $UserAutocompleteFields, { EmailAddress => 'STARTSWITH', Name => 'STARTSWITH', RealName => 'LIKE' })] ) >>
 
 =cut
 
-Set( $UserAutocompleteFields, [qw(EmailAddress Name RealName)] );
+Set( $UserAutocompleteFields, {
+    EmailAddress => 'STARTSWITH',
+    Name         => 'STARTSWITH',
+    RealName     => 'LIKE',
+});
 
 =item C<$AllowUserAutocompleteForUnprivileged>
 
diff --git a/share/html/Helpers/Autocomplete/Owners b/share/html/Helpers/Autocomplete/Owners
index 84c64ab..8aad1a9 100644
--- a/share/html/Helpers/Autocomplete/Owners
+++ b/share/html/Helpers/Autocomplete/Owners
@@ -67,8 +67,8 @@ $m->abort unless defined $return
 
 my $CurrentUser = $session{'CurrentUser'};
 
-my @fields = @{ RT->Config->Get('UserAutocompleteFields')
-                || [qw(EmailAddress Name RealName)] };
+my %fields = %{ RT->Config->Get('UserAutocompleteFields')
+                || { EmailAddress => 1, Name => 1, RealName => 'LIKE' } };
 
 my %user_uniq_hash;
 my $isSU = $session{CurrentUser}
@@ -93,10 +93,13 @@ foreach my $spec (map { [split /\-/, $_, 2] } split /\|/, $limit) {
 
     # Limit by our autocomplete term BEFORE we limit to OwnTicket because that
     # does a funky union hack
-    for (@fields) {
+    while (my ($name, $op) = each %fields) {
+        $op = 'STARTSWITH'
+            unless $op =~ /^(?:LIKE|(?:START|END)SWITH)$/i;
+
         $Users->Limit(
-            FIELD           => $_,
-            OPERATOR        => 'LIKE',
+            FIELD           => $name,
+            OPERATOR        => $op,
             VALUE           => $term,
             ENTRYAGGREGATOR => 'OR',
             SUBCLAUSE       => 'autocomplete',
diff --git a/share/html/Helpers/Autocomplete/Users b/share/html/Helpers/Autocomplete/Users
index bbf1f00..715bb03 100644
--- a/share/html/Helpers/Autocomplete/Users
+++ b/share/html/Helpers/Autocomplete/Users
@@ -83,16 +83,19 @@ my $CurrentUser = $session{'CurrentUser'};
 $m->abort unless $CurrentUser->Privileged
               or RT->Config->Get('AllowUserAutocompleteForUnprivileged');
 
-my @fields = @{ RT->Config->Get('UserAutocompleteFields')
-                || [qw(EmailAddress Name RealName)] };
+my %fields = %{ RT->Config->Get('UserAutocompleteFields')
+                || { EmailAddress => 1, Name => 1, RealName => 'LIKE' } };
 
 my $users = RT::Users->new( $CurrentUser );
 $users->RowsPerPage( $max );
 
-for (@fields) {
+while (my ($name, $op) = each %fields) {
+    $op = 'STARTSWITH'
+        unless $op =~ /^(?:LIKE|(?:START|END)SWITH)$/i;
+
     $users->Limit(
-        FIELD           => $_,
-        OPERATOR        => 'LIKE',
+        FIELD           => $name,
+        OPERATOR        => $op,
         VALUE           => $term,
         ENTRYAGGREGATOR => 'OR',
         SUBCLAUSE       => 'autocomplete',

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


More information about the Rt-commit mailing list