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:
Steve Howell
2017-08-22 15:41:08 -04:00
committed by Tim Abbott
parent 480d642eff
commit 313f73258d
3 changed files with 45 additions and 7 deletions

View File

@@ -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