[Rt-commit] rt branch, 4.4/search-watcher-by-group-name, created. rt-4.4.4-146-g5fa47b1d2f

? sunnavy sunnavy at bestpractical.com
Mon Nov 2 16:23:16 EST 2020


The branch, 4.4/search-watcher-by-group-name has been created
        at  5fa47b1d2fd2118574f24d8bdeaa2ca733d77f07 (commit)

- Log -----------------------------------------------------------------
commit 5fa47b1d2fd2118574f24d8bdeaa2ca733d77f07
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Nov 3 05:00:16 2020 +0800

    Support to search user defined group names in watcher limit
    
    To search tickets that have a specified group in a role, previously we
    had to specify the group id like "AdminCc.id = 123", which is not
    convenient. Here we support group names to improve this, e.g.
    "AdminCc.Name = 'team foo'".
    
    In case the name in question is shared by a user and a group(which is
    weird and should be quite rare in real world), both will be respected.
    I.e. we return tickets that have either the user or the group in the
    role.

diff --git a/lib/RT/SearchBuilder/Role/Roles.pm b/lib/RT/SearchBuilder/Role/Roles.pm
index 5980882d31..ac6863113f 100644
--- a/lib/RT/SearchBuilder/Role/Roles.pm
+++ b/lib/RT/SearchBuilder/Role/Roles.pm
@@ -235,7 +235,7 @@ sub RoleLimit {
 
     my $column = $type ? $class->Role($type)->{Column} : undef;
 
-    # if it's equality op and search by Email or Name then we can preload user
+    # if it's equality op and search by Email or Name then we can preload user/group
     # we do it to help some DBs better estimate number of rows and get better plans
     if ( $args{OPERATOR} =~ /^!?=$/
              && (!$args{FIELD} || $args{FIELD} eq 'Name' || $args{FIELD} eq 'EmailAddress') ) {
@@ -245,8 +245,27 @@ sub RoleLimit {
             ? ($column ? 'Load' : 'LoadByEmail')
             : $args{FIELD} eq 'EmailAddress' ? 'LoadByEmail': 'Load';
         $o->$method( $args{VALUE} );
+        my @values;
+        @values = $o->Id if $o->Id;
+
+        if ( ( !$args{FIELD} || $args{FIELD} eq 'Name' ) ) {
+            my $group = RT::Group->new( $self->CurrentUser );
+            $group->LoadUserDefinedGroup( $args{VALUE} );
+            push @values, $group->Id if $group->Id;
+        }
+
         $args{FIELD} = 'id';
-        $args{VALUE} = $o->id || 0;
+        if ( @values == 1 ) {
+            $args{VALUE} = $values[0];
+        }
+        elsif ( @values > 1 ) {
+            RT->Logger->debug("Name $args{VALUE} is used in both user and group");
+            $args{VALUE} = \@values;
+            $args{OPERATOR} = $args{OPERATOR} =~ /!/ ? 'NOT IN' : 'IN';
+        }
+        else {
+            $args{VALUE} = 0;
+        }
     }
 
     if ( $column and $args{FIELD} and $args{FIELD} eq 'id' ) {

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


More information about the rt-commit mailing list