From fd70e83980ebe1f7c2a1a6c19225e1144ca458b9 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Mon, 3 Feb 2025 19:20:11 +0530 Subject: [PATCH] streams: Fix incorrect setting value in stream creation event. Value for "can_administer_channel_group" passed in stream creation event was incorrect when there was no value passed for the setting while creating the stream and thus the setting was set to anonymous group containing stream creator as default. This was because code for creating setting_groups_dict, which is used to send setting values in the stream creation event, incorrectly assumed that defaults for all settings is a system group. This was not noticed before because we pass all the settings when creating streams using webapp, but can be reproduced by creating streams using API without passing any value for "can_administer_channel_group". --- zerver/views/streams.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/zerver/views/streams.py b/zerver/views/streams.py index 7c0feb20bc..daadacdbc0 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -617,9 +617,16 @@ def add_subscriptions_backend( group_settings_map[setting_name] = get_stream_permission_default_group( setting_name, system_groups_name_dict, creator=user_profile ) - setting_groups_dict[group_settings_map[setting_name].id] = group_settings_map[ - setting_name - ].id + if permission_configuration.default_group_name == "stream_creator_or_nobody": + # Default for some settings like "can_administer_channel_group" + # is anonymous group with stream creator. + setting_groups_dict[group_settings_map[setting_name].id] = ( + AnonymousSettingGroupDict(direct_subgroups=[], direct_members=[user_profile.id]) + ) + else: + setting_groups_dict[group_settings_map[setting_name].id] = group_settings_map[ + setting_name + ].id for stream_obj in streams_raw: # 'color' field is optional