mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
addressee: Accept a realm object in legacy_build.
This fixes a bug where the internal_prep_message code path would incorrectly ignore the `realm` that was passed into it. As a result, attempts to send messages using the system bots with this code path would crash. As a sidenote, we really need to make our test system consistent with production in terms of whether the user's realm is the same as the system realm.
This commit is contained in:
@@ -1643,7 +1643,8 @@ def internal_prep_message(realm, sender_email, recipient_type_name, recipients,
|
||||
sender,
|
||||
recipient_type_name,
|
||||
parsed_recipients,
|
||||
subject)
|
||||
subject,
|
||||
realm=realm)
|
||||
|
||||
return _internal_prep_message(
|
||||
realm=realm,
|
||||
|
||||
@@ -80,12 +80,15 @@ class Addressee(object):
|
||||
return self._topic
|
||||
|
||||
@staticmethod
|
||||
def legacy_build(sender, message_type_name, message_to, topic_name):
|
||||
# type: (UserProfile, Text, Sequence[Text], Text) -> Addressee
|
||||
def legacy_build(sender, message_type_name, message_to, topic_name, realm=None):
|
||||
# type: (UserProfile, Text, Sequence[Text], Text, Optional[Realm]) -> Addressee
|
||||
|
||||
# For legacy reason message_to used to be either a list of
|
||||
# emails or a list of streams. We haven't fixed all of our
|
||||
# callers yet.
|
||||
if realm is None:
|
||||
realm = sender.realm
|
||||
|
||||
if message_type_name == 'stream':
|
||||
if len(message_to) > 1:
|
||||
raise JsonableError(_("Cannot send to multiple streams"))
|
||||
@@ -101,7 +104,7 @@ class Addressee(object):
|
||||
return Addressee.for_stream(stream_name, topic_name)
|
||||
elif message_type_name == 'private':
|
||||
emails = message_to
|
||||
return Addressee.for_private(emails, sender.realm)
|
||||
return Addressee.for_private(emails, realm)
|
||||
else:
|
||||
raise JsonableError(_("Invalid message type"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user