diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py index fc071d39a1..53b3a0b711 100644 --- a/zerver/lib/streams.py +++ b/zerver/lib/streams.py @@ -997,6 +997,15 @@ def check_stream_name_available(realm: Realm, name: str) -> None: pass +def check_zephyr_realm_invite_conditions( + is_subscribing_other_users: bool, realm: Realm, invite_only: bool +) -> None: + if is_subscribing_other_users and realm.is_zephyr_mirror_realm and not invite_only: + raise JsonableError( + _("You can only invite other Zephyr mirroring users to private channels.") + ) + + def access_stream_by_name( user_profile: UserProfile, stream_name: str, diff --git a/zerver/views/streams.py b/zerver/views/streams.py index b1f5b0455f..97d5d65cf7 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -75,6 +75,7 @@ from zerver.lib.streams import ( access_web_public_stream, channel_events_topic_name, check_stream_name_available, + check_zephyr_realm_invite_conditions, do_get_streams, filter_stream_authorization_for_adding_subscribers, get_anonymous_group_membership_dict_for_streams, @@ -844,14 +845,8 @@ def add_subscriptions_backend( # Newly created streams are also authorized for the creator streams = authorized_streams + created_streams - if ( - is_subscribing_other_users - and realm.is_zephyr_mirror_realm - and not all(stream.invite_only for stream in streams) - ): - raise JsonableError( - _("You can only invite other Zephyr mirroring users to private channels.") - ) + for stream in streams: + check_zephyr_realm_invite_conditions(is_subscribing_other_users, realm, stream.invite_only) if is_subscribing_other_users: subscribers = bulk_principals_to_user_profiles(principals, user_profile)