mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
remove_users_from_stream: Replace get_user_profile_by_email with get_user.
This commit is contained in:
@@ -3,26 +3,17 @@ from __future__ import print_function
|
||||
|
||||
from typing import Any
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandParser
|
||||
from django.core.management.base import CommandParser
|
||||
|
||||
from zerver.lib.actions import bulk_remove_subscriptions
|
||||
from zerver.models import Realm, UserProfile, get_realm, get_stream, \
|
||||
get_user_profile_by_email
|
||||
from zerver.lib.management import ZulipBaseCommand
|
||||
from zerver.models import UserProfile, get_stream
|
||||
|
||||
class Command(BaseCommand):
|
||||
class Command(ZulipBaseCommand):
|
||||
help = """Remove some or all users in a realm from a stream."""
|
||||
|
||||
def add_arguments(self, parser):
|
||||
# type: (CommandParser) -> None
|
||||
parser.add_argument('-r', '--realm',
|
||||
dest='string_id',
|
||||
type=str,
|
||||
help='The subdomain or string_id of the realm in which you are '
|
||||
'removing people.')
|
||||
|
||||
parser.add_argument('-s', '--stream',
|
||||
dest='stream',
|
||||
type=str,
|
||||
@@ -38,15 +29,17 @@ class Command(BaseCommand):
|
||||
action="store_true",
|
||||
default=False,
|
||||
help='Remove all users in this realm from this stream.')
|
||||
self.add_realm_args(parser, True)
|
||||
|
||||
def handle(self, **options):
|
||||
# type: (**Any) -> None
|
||||
if options["string_id"] is None or options["stream"] is None or \
|
||||
(options["users"] is None and options["all_users"] is None):
|
||||
realm = self.get_realm(options)
|
||||
|
||||
if realm is None or options["stream"] is None or \
|
||||
(options["users"] is None and not options["all_users"]):
|
||||
self.print_help("./manage.py", "remove_users_from_stream")
|
||||
exit(1)
|
||||
|
||||
realm = get_realm(options["string_id"])
|
||||
stream_name = options["stream"].strip()
|
||||
stream = get_stream(stream_name, realm)
|
||||
|
||||
@@ -56,7 +49,7 @@ class Command(BaseCommand):
|
||||
emails = set([email.strip() for email in options["users"].split(",")])
|
||||
user_profiles = []
|
||||
for email in emails:
|
||||
user_profiles.append(get_user_profile_by_email(email))
|
||||
user_profiles.append(self.get_user(email, realm))
|
||||
|
||||
result = bulk_remove_subscriptions(user_profiles, [stream])
|
||||
not_subscribed = result[1]
|
||||
|
||||
Reference in New Issue
Block a user