mirror of https://github.com/zulip/zulip.git
send_pm_if_empty_stream: Use realm object to check cross-realm.
The previous check didn't work correctly in the event that the target stream did not exist.
This commit is contained in:
parent
4cfcc70e78
commit
b09c2369c1
|
@ -1101,9 +1101,11 @@ def check_stream_name(stream_name):
|
||||||
if not valid_stream_name(stream_name):
|
if not valid_stream_name(stream_name):
|
||||||
raise JsonableError(_("Invalid stream name"))
|
raise JsonableError(_("Invalid stream name"))
|
||||||
|
|
||||||
def send_pm_if_empty_stream(sender, stream, stream_name):
|
def send_pm_if_empty_stream(sender, stream, stream_name, realm):
|
||||||
# type: (UserProfile, Stream, text_type) -> None
|
# type: (UserProfile, Stream, text_type, Realm) -> None
|
||||||
# TODO: It's not clear whether stream can be None. Some cleanup is needed.
|
"""If a bot sends a message to a stream that doesn't exist or has no
|
||||||
|
subscribers, sends a notification to the bot owner (if not a
|
||||||
|
cross-realm bot) so that the owner can correct the issue."""
|
||||||
if sender.realm.is_zephyr_mirror_realm or sender.realm.deactivated:
|
if sender.realm.is_zephyr_mirror_realm or sender.realm.deactivated:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1112,7 +1114,7 @@ def send_pm_if_empty_stream(sender, stream, stream_name):
|
||||||
# (e.g. from EMAIL_GATEWAY_BOT) since the owner for
|
# (e.g. from EMAIL_GATEWAY_BOT) since the owner for
|
||||||
# EMAIL_GATEWAY_BOT is probably the server administrator, not
|
# EMAIL_GATEWAY_BOT is probably the server administrator, not
|
||||||
# the owner of the bot who could potentially fix the problem.
|
# the owner of the bot who could potentially fix the problem.
|
||||||
if stream is not None and stream.realm != sender.realm:
|
if sender.realm != realm:
|
||||||
return
|
return
|
||||||
|
|
||||||
if stream:
|
if stream:
|
||||||
|
@ -1182,7 +1184,7 @@ def check_message(sender, client, message_type_name, message_to,
|
||||||
|
|
||||||
stream = get_stream(stream_name, realm)
|
stream = get_stream(stream_name, realm)
|
||||||
|
|
||||||
send_pm_if_empty_stream(sender, stream, stream_name)
|
send_pm_if_empty_stream(sender, stream, stream_name, realm)
|
||||||
|
|
||||||
if stream is None:
|
if stream is None:
|
||||||
raise JsonableError(_("Stream does not exist"))
|
raise JsonableError(_("Stream does not exist"))
|
||||||
|
|
Loading…
Reference in New Issue