mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	streams: Extract zephyr realm invite check.
This will be reused later in the `/channels/create` view. Signed-off-by: apoorvapendse <apoorvavpendse@gmail.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							1190afbe4f
						
					
				
				
					commit
					4d49fa6fbb
				
			@@ -997,6 +997,15 @@ def check_stream_name_available(realm: Realm, name: str) -> None:
 | 
				
			|||||||
        pass
 | 
					        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(
 | 
					def access_stream_by_name(
 | 
				
			||||||
    user_profile: UserProfile,
 | 
					    user_profile: UserProfile,
 | 
				
			||||||
    stream_name: str,
 | 
					    stream_name: str,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -75,6 +75,7 @@ from zerver.lib.streams import (
 | 
				
			|||||||
    access_web_public_stream,
 | 
					    access_web_public_stream,
 | 
				
			||||||
    channel_events_topic_name,
 | 
					    channel_events_topic_name,
 | 
				
			||||||
    check_stream_name_available,
 | 
					    check_stream_name_available,
 | 
				
			||||||
 | 
					    check_zephyr_realm_invite_conditions,
 | 
				
			||||||
    do_get_streams,
 | 
					    do_get_streams,
 | 
				
			||||||
    filter_stream_authorization_for_adding_subscribers,
 | 
					    filter_stream_authorization_for_adding_subscribers,
 | 
				
			||||||
    get_anonymous_group_membership_dict_for_streams,
 | 
					    get_anonymous_group_membership_dict_for_streams,
 | 
				
			||||||
@@ -844,14 +845,8 @@ def add_subscriptions_backend(
 | 
				
			|||||||
    # Newly created streams are also authorized for the creator
 | 
					    # Newly created streams are also authorized for the creator
 | 
				
			||||||
    streams = authorized_streams + created_streams
 | 
					    streams = authorized_streams + created_streams
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (
 | 
					    for stream in streams:
 | 
				
			||||||
        is_subscribing_other_users
 | 
					        check_zephyr_realm_invite_conditions(is_subscribing_other_users, realm, stream.invite_only)
 | 
				
			||||||
        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.")
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if is_subscribing_other_users:
 | 
					    if is_subscribing_other_users:
 | 
				
			||||||
        subscribers = bulk_principals_to_user_profiles(principals, user_profile)
 | 
					        subscribers = bulk_principals_to_user_profiles(principals, user_profile)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user