Skip to content

Commit

Permalink
Tweak role member's "NULL" searches
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sunnavy committed Oct 23, 2024
1 parent fe05866 commit d137e6f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/RT/SearchBuilder/Role/Roles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit d137e6f

Please sign in to comment.