mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	stream settings: Allow realm admins to access all private stream subs.
This will allow realm admins to access subscribers of unsubscribed private stream. This is a preparatory commit for letting realm admins remove those users.
This commit is contained in:
		@@ -29,9 +29,12 @@ def access_stream_for_delete_or_update(user_profile: UserProfile, stream_id: int
 | 
			
		||||
 | 
			
		||||
    return stream
 | 
			
		||||
 | 
			
		||||
# Only set allow_realm_admin flag to True when you want to allow realm admin to
 | 
			
		||||
# access unsubscribed private stream content.
 | 
			
		||||
def access_stream_common(user_profile: UserProfile, stream: Stream,
 | 
			
		||||
                         error: Text,
 | 
			
		||||
                         require_active: bool=True) -> Tuple[Recipient, Subscription]:
 | 
			
		||||
                         require_active: bool=True,
 | 
			
		||||
                         allow_realm_admin: bool=False) -> Tuple[Recipient, Subscription]:
 | 
			
		||||
    """Common function for backend code where the target use attempts to
 | 
			
		||||
    access the target stream, returning all the data fetched along the
 | 
			
		||||
    way.  If that user does not have permission to access that stream,
 | 
			
		||||
@@ -59,13 +62,21 @@ def access_stream_common(user_profile: UserProfile, stream: Stream,
 | 
			
		||||
    if sub is not None:
 | 
			
		||||
        return (recipient, sub)
 | 
			
		||||
 | 
			
		||||
    # For some specific callers (e.g. getting list of subscribers,
 | 
			
		||||
    # removing other users from a stream, and updating stream name and
 | 
			
		||||
    # description), we allow realm admins to access stream even if
 | 
			
		||||
    # they are not subscribed to a private stream.
 | 
			
		||||
    if user_profile.is_realm_admin and allow_realm_admin:
 | 
			
		||||
        return (recipient, sub)
 | 
			
		||||
 | 
			
		||||
    # Otherwise it is a private stream and you're not on it, so throw
 | 
			
		||||
    # an error.
 | 
			
		||||
    raise JsonableError(error)
 | 
			
		||||
 | 
			
		||||
def access_stream_by_id(user_profile: UserProfile,
 | 
			
		||||
                        stream_id: int,
 | 
			
		||||
                        require_active: bool=True) -> Tuple[Stream, Recipient, Subscription]:
 | 
			
		||||
                        require_active: bool=True,
 | 
			
		||||
                        allow_realm_admin: bool=False) -> Tuple[Stream, Recipient, Subscription]:
 | 
			
		||||
    error = _("Invalid stream id")
 | 
			
		||||
    try:
 | 
			
		||||
        stream = Stream.objects.get(id=stream_id)
 | 
			
		||||
@@ -73,7 +84,8 @@ def access_stream_by_id(user_profile: UserProfile,
 | 
			
		||||
        raise JsonableError(error)
 | 
			
		||||
 | 
			
		||||
    (recipient, sub) = access_stream_common(user_profile, stream, error,
 | 
			
		||||
                                            require_active=require_active)
 | 
			
		||||
                                            require_active=require_active,
 | 
			
		||||
                                            allow_realm_admin=allow_realm_admin)
 | 
			
		||||
    return (stream, recipient, sub)
 | 
			
		||||
 | 
			
		||||
def check_stream_name_available(realm: Realm, name: Text) -> None:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user