mention_dataset: Add query to mention cross realm bots as pill.

Previously, cross realm bots were not displayed as mention Pills.

This is because, the data set for validating mentions considers
only the realm id which is None in case of cross realm bots.

Hence, adding an or Q object to it, to also check if
the email is a part of the cross realm bots email, in case the
realm id returns None.

Fixes #26913
This commit is contained in:
roanster007
2023-11-03 11:40:19 +05:30
committed by Tim Abbott
parent 826f25744d
commit ac084ddb0e

View File

@@ -3,6 +3,7 @@ import re
from dataclasses import dataclass from dataclasses import dataclass
from typing import Dict, List, Match, Optional, Set, Tuple from typing import Dict, List, Match, Optional, Set, Tuple
from django.conf import settings
from django.db.models import Q from django.db.models import Q
from zerver.models import UserGroup, UserProfile, get_linkable_streams from zerver.models import UserGroup, UserProfile, get_linkable_streams
@@ -91,9 +92,9 @@ class MentionBackend:
rows = ( rows = (
UserProfile.objects.filter( UserProfile.objects.filter(
realm_id=self.realm_id, Q(realm_id=self.realm_id) | Q(email__in=settings.CROSS_REALM_BOT_EMAILS),
is_active=True,
) )
.filter(is_active=True)
.filter( .filter(
functools.reduce(lambda a, b: a | b, q_list), functools.reduce(lambda a, b: a | b, q_list),
) )