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