mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Allow admins to delete private streams (backend only).
This is the backend piece. Getting the UI right here is a bit more complicated here, but this allows admins to use the API to delete streams.
This commit is contained in:
		@@ -11,6 +11,26 @@ from zerver.models import UserProfile, Stream, Subscription, \
 | 
			
		||||
    Realm, Recipient, bulk_get_recipients, get_recipient, get_stream, \
 | 
			
		||||
    bulk_get_streams
 | 
			
		||||
 | 
			
		||||
def access_stream_for_delete(user_profile, stream_id):
 | 
			
		||||
    # type: (UserProfile, int) -> Stream
 | 
			
		||||
 | 
			
		||||
    # We should only ever use this for realm admins, who are allowed
 | 
			
		||||
    # to delete all streams on their realm, even private streams to
 | 
			
		||||
    # which they are not subscribed.  We do an assert here, because
 | 
			
		||||
    # all callers should have the require_realm_admin decorator.
 | 
			
		||||
    assert(user_profile.is_realm_admin)
 | 
			
		||||
 | 
			
		||||
    error = _("Invalid stream id")
 | 
			
		||||
    try:
 | 
			
		||||
        stream = Stream.objects.get(id=stream_id)
 | 
			
		||||
    except Stream.DoesNotExist:
 | 
			
		||||
        raise JsonableError(error)
 | 
			
		||||
 | 
			
		||||
    if stream.realm_id != user_profile.realm_id:
 | 
			
		||||
        raise JsonableError(error)
 | 
			
		||||
 | 
			
		||||
    return stream
 | 
			
		||||
 | 
			
		||||
def access_stream_common(user_profile, stream, error):
 | 
			
		||||
    # type: (UserProfile, Stream, Text) -> Tuple[Recipient, Subscription]
 | 
			
		||||
    """Common function for backend code where the target use attempts to
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user