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:
Tim Abbott
2017-09-25 12:55:02 -07:00
parent cc6d35c0f2
commit c11b1623dd
2 changed files with 8 additions and 4 deletions

View File

@@ -1643,7 +1643,8 @@ def internal_prep_message(realm, sender_email, recipient_type_name, recipients,
sender, sender,
recipient_type_name, recipient_type_name,
parsed_recipients, parsed_recipients,
subject) subject,
realm=realm)
return _internal_prep_message( return _internal_prep_message(
realm=realm, realm=realm,

View File

@@ -80,12 +80,15 @@ class Addressee(object):
return self._topic return self._topic
@staticmethod @staticmethod
def legacy_build(sender, message_type_name, message_to, topic_name): def legacy_build(sender, message_type_name, message_to, topic_name, realm=None):
# type: (UserProfile, Text, Sequence[Text], Text) -> Addressee # type: (UserProfile, Text, Sequence[Text], Text, Optional[Realm]) -> Addressee
# For legacy reason message_to used to be either a list of # 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 # emails or a list of streams. We haven't fixed all of our
# callers yet. # callers yet.
if realm is None:
realm = sender.realm
if message_type_name == 'stream': if message_type_name == 'stream':
if len(message_to) > 1: if len(message_to) > 1:
raise JsonableError(_("Cannot send to multiple streams")) raise JsonableError(_("Cannot send to multiple streams"))
@@ -101,7 +104,7 @@ class Addressee(object):
return Addressee.for_stream(stream_name, topic_name) return Addressee.for_stream(stream_name, topic_name)
elif message_type_name == 'private': elif message_type_name == 'private':
emails = message_to emails = message_to
return Addressee.for_private(emails, sender.realm) return Addressee.for_private(emails, realm)
else: else:
raise JsonableError(_("Invalid message type")) raise JsonableError(_("Invalid message type"))