mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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:
		@@ -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."))
 | 
			
		||||
 
 | 
			
		||||
@@ -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="",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user