mirror of https://github.com/zulip/zulip.git
mention: Use NamedUserGroup objects in mention code.
This commit is contained in:
parent
0ff9aacb96
commit
dfeb896107
|
@ -7,7 +7,7 @@ from django.conf import settings
|
|||
from django.db.models import Q
|
||||
|
||||
from zerver.lib.users import get_inaccessible_user_ids
|
||||
from zerver.models import UserGroup, UserProfile
|
||||
from zerver.models import NamedUserGroup, UserProfile
|
||||
from zerver.models.streams import get_linkable_streams
|
||||
|
||||
BEFORE_MENTION_ALLOWED_REGEX = r"(?<![^\s\'\"\(\{\[\/<])"
|
||||
|
@ -265,11 +265,11 @@ class MentionData:
|
|||
return self.has_topic_wildcards
|
||||
|
||||
def init_user_group_data(self, realm_id: int, content: str) -> None:
|
||||
self.user_group_name_info: Dict[str, UserGroup] = {}
|
||||
self.user_group_name_info: Dict[str, NamedUserGroup] = {}
|
||||
self.user_group_members: Dict[int, List[int]] = {}
|
||||
user_group_names = possible_user_group_mentions(content)
|
||||
if user_group_names:
|
||||
for group in UserGroup.objects.filter(
|
||||
for group in NamedUserGroup.objects.filter(
|
||||
realm_id=realm_id, name__in=user_group_names, is_system_group=False
|
||||
).prefetch_related("direct_members"):
|
||||
self.user_group_name_info[group.name.lower()] = group
|
||||
|
@ -293,7 +293,7 @@ class MentionData:
|
|||
"""
|
||||
return set(self.user_id_info.keys())
|
||||
|
||||
def get_user_group(self, name: str) -> Optional[UserGroup]:
|
||||
def get_user_group(self, name: str) -> Optional[NamedUserGroup]:
|
||||
return self.user_group_name_info.get(name.lower(), None)
|
||||
|
||||
def get_group_members(self, user_group_id: int) -> List[int]:
|
||||
|
|
|
@ -47,11 +47,11 @@ from zerver.lib.user_topics import build_get_topic_visibility_policy, get_topic_
|
|||
from zerver.lib.users import get_inaccessible_user_ids
|
||||
from zerver.models import (
|
||||
Message,
|
||||
NamedUserGroup,
|
||||
Realm,
|
||||
Recipient,
|
||||
Stream,
|
||||
Subscription,
|
||||
UserGroup,
|
||||
UserMessage,
|
||||
UserProfile,
|
||||
UserTopic,
|
||||
|
@ -1213,7 +1213,7 @@ def stream_wildcard_mention_allowed(sender: UserProfile, stream: Stream, realm:
|
|||
|
||||
|
||||
def check_user_group_mention_allowed(sender: UserProfile, user_group_ids: List[int]) -> None:
|
||||
user_groups = UserGroup.objects.filter(id__in=user_group_ids).select_related(
|
||||
user_groups = NamedUserGroup.objects.filter(id__in=user_group_ids).select_related(
|
||||
"can_mention_group"
|
||||
)
|
||||
sender_is_system_bot = is_cross_realm_bot_email(sender.delivery_email)
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Any, Collection, Dict, List, Optional, Set
|
|||
|
||||
from zerver.lib.mention import MentionData
|
||||
from zerver.lib.user_groups import get_user_group_member_ids
|
||||
from zerver.models import UserGroup, UserProfile, UserTopic
|
||||
from zerver.models import NamedUserGroup, UserProfile, UserTopic
|
||||
from zerver.models.scheduled_jobs import NotificationTriggers
|
||||
|
||||
|
||||
|
@ -352,7 +352,7 @@ def get_mentioned_user_group(
|
|||
# all these messages.
|
||||
smallest_user_group_size = math.inf
|
||||
for user_group_id in mentioned_user_group_ids:
|
||||
current_user_group = UserGroup.objects.get(id=user_group_id, realm=user_profile.realm)
|
||||
current_user_group = NamedUserGroup.objects.get(id=user_group_id, realm=user_profile.realm)
|
||||
current_mentioned_user_group = MentionedUserGroup(
|
||||
id=current_user_group.id,
|
||||
name=current_user_group.name,
|
||||
|
|
|
@ -17,4 +17,11 @@ class Migration(migrations.Migration):
|
|||
null=True, on_delete=django.db.models.deletion.CASCADE, to="zerver.namedusergroup"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="scheduledmessagenotificationemail",
|
||||
name="mentioned_user_group",
|
||||
field=models.ForeignKey(
|
||||
null=True, on_delete=django.db.models.deletion.CASCADE, to="zerver.namedusergroup"
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -13,7 +13,7 @@ from zerver.lib.display_recipient import get_recipient_ids
|
|||
from zerver.lib.timestamp import datetime_to_timestamp
|
||||
from zerver.models.clients import Client
|
||||
from zerver.models.constants import MAX_TOPIC_NAME_LENGTH
|
||||
from zerver.models.groups import UserGroup
|
||||
from zerver.models.groups import NamedUserGroup
|
||||
from zerver.models.messages import Message
|
||||
from zerver.models.realms import Realm
|
||||
from zerver.models.recipients import Recipient
|
||||
|
@ -113,7 +113,7 @@ class ScheduledMessageNotificationEmail(models.Model):
|
|||
]
|
||||
|
||||
trigger = models.TextField(choices=EMAIL_NOTIFICATION_TRIGGER_CHOICES)
|
||||
mentioned_user_group = models.ForeignKey(UserGroup, null=True, on_delete=CASCADE)
|
||||
mentioned_user_group = models.ForeignKey(NamedUserGroup, null=True, on_delete=CASCADE)
|
||||
|
||||
# Timestamp for when the notification should be processed and sent.
|
||||
# Calculated from the time the event was received and the batching period.
|
||||
|
|
Loading…
Reference in New Issue