From d137e6fd653b79ab225b50ab8fa1bf9bc9fd166f Mon Sep 17 00:00:00 2001 From: sunnavy Date: Tue, 22 Oct 2024 19:46:45 -0400 Subject: [PATCH] Tweak role member's "NULL" searches Previously, "IS NULL" meant that role doesn't have any members. Sometimes users actually mean that the role does have members, it's just the specified field of the members is NULL. Requestor.CustomField.Manager IS NULL This commit tweaks NULL searches and splits it into 2 cases: * The ticket doesn't have any requestors Requestor IS NULL Requestor.id IS NULL Requestor.Name IS NULL * At least one of the ticket requestors has NULL in specified user fields. Requestor.City IS NULL Requestor.CustomField.Manager IS NULL --- lib/RT/SearchBuilder/Role/Roles.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/RT/SearchBuilder/Role/Roles.pm b/lib/RT/SearchBuilder/Role/Roles.pm index 35393692c19..7fa553b93cb 100644 --- a/lib/RT/SearchBuilder/Role/Roles.pm +++ b/lib/RT/SearchBuilder/Role/Roles.pm @@ -306,7 +306,7 @@ sub RoleLimit { } $self->_OpenParen( $args{SUBCLAUSE} ) if $args{SUBCLAUSE}; - if ( $args{OPERATOR} =~ /^IS(?: NOT)?$/i ) { + if ( $args{OPERATOR} =~ /^IS(?: NOT)?$/i && ( $args{FIELD} =~ /^(?:id|Name)$/ ) ) { # is [not] empty case $group_members ||= $self->_GroupMembersJoin( GroupsAlias => $groups ); @@ -571,6 +571,7 @@ sub RoleLimit { if ( $cf->id && $cf->CurrentUserHasRight('SeeCustomField') ) { my $ocfvs = $self->NewAlias('ObjectCustomFieldValues'); $self->Join( + TYPE => 'LEFT', ALIAS1 => $users, FIELD1 => 'id', ALIAS2 => $ocfvs, @@ -618,6 +619,16 @@ sub RoleLimit { CASESENSITIVE => 0, ); } + + $self->Limit( + %args, + ALIAS => $users, + FIELD => 'id', + OPERATOR => 'IS NOT', + VALUE => 'NULL', + CASESENSITIVE => 0, + ENTRYAGGREGATOR => 'AND', + ); } } $self->_CloseParen( $args{SUBCLAUSE} ) if $args{SUBCLAUSE};