stream: Fix error handling in access_stream_for_send_message.

According to tests we should not allow bot without owners to
post in streams with STREAM_POST_POLICY_RESTRICT_NEW_MEMBERS.
But the code does not handle this and the related test passes
and raises error for case of bots without owner because the bot
is itself a new member.

This commit fixes this by adding a condition to check if there
is no bot owner and then raise error if there is no owner.
This commit is contained in:
sahil839 2021-01-07 01:07:38 +05:30 committed by Tim Abbott
parent e865e3156d
commit 3df87d0901
2 changed files with 3 additions and 2 deletions

View File

@ -205,7 +205,7 @@ def access_stream_for_send_message(
elif stream.stream_post_policy != Stream.STREAM_POST_POLICY_EVERYONE and sender.is_guest:
raise JsonableError(_("Guests cannot send to this stream."))
elif stream.stream_post_policy == Stream.STREAM_POST_POLICY_RESTRICT_NEW_MEMBERS:
if sender.is_bot and (sender.bot_owner is not None and sender.bot_owner.is_new_member):
if sender.is_bot and (sender.bot_owner is None or sender.bot_owner.is_new_member):
raise JsonableError(_("New members cannot send to this stream."))
elif sender.is_new_member:
raise JsonableError(_("New members cannot send to this stream."))

View File

@ -279,7 +279,8 @@ class MessagePOSTTest(ZulipTestCase):
non_admin_owned_bot, stream_name, "New members cannot send to this stream."
)
# Bots without owner (except cross realm bot) cannot send to announcement only stream
# Bots without owner (except cross realm bot) cannot send to STREAM_POST_POLICY_ADMINS_ONLY and
# STREAM_POST_POLICY_RESTRICT_NEW_MEMBERS streams
bot_without_owner = do_create_user(
email="free-bot@zulip.testserver",
password="",