2013-10-10 21:37:26 +02:00
|
|
|
|
2017-11-16 00:43:27 +01:00
|
|
|
import sys
|
2016-12-14 19:40:04 +01:00
|
|
|
from argparse import ArgumentParser, RawTextHelpFormatter
|
2018-05-10 19:30:04 +02:00
|
|
|
from typing import Any, Dict
|
2016-06-04 16:52:18 +02:00
|
|
|
|
2013-11-22 22:09:47 +01:00
|
|
|
from zerver.lib.actions import set_default_streams
|
2017-08-07 22:26:52 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2012-11-27 18:26:51 +01:00
|
|
|
|
2017-08-07 22:26:52 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2012-11-27 18:26:51 +01:00
|
|
|
help = """Set default streams for a realm
|
|
|
|
|
|
|
|
Users created under this realm will start out with these streams. This
|
2017-03-14 23:43:47 +01:00
|
|
|
command is not additive: if you re-run it on a realm with a different
|
2012-11-27 18:26:51 +01:00
|
|
|
set of default streams, those will be the new complete set of default
|
|
|
|
streams.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2016-11-16 21:16:02 +01:00
|
|
|
./manage.py set_default_streams --realm=foo --streams=foo,bar,baz
|
|
|
|
./manage.py set_default_streams --realm=foo --streams="foo,bar,baz with space"
|
|
|
|
./manage.py set_default_streams --realm=foo --streams=
|
2012-11-27 18:26:51 +01:00
|
|
|
"""
|
|
|
|
|
2016-12-14 19:40:04 +01:00
|
|
|
# Fix support for multi-line usage
|
2017-10-26 11:35:57 +02:00
|
|
|
def create_parser(self, *args: Any, **kwargs: Any) -> ArgumentParser:
|
2017-10-27 08:28:23 +02:00
|
|
|
parser = super().create_parser(*args, **kwargs)
|
2016-12-14 19:40:04 +01:00
|
|
|
parser.formatter_class = RawTextHelpFormatter
|
|
|
|
return parser
|
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2016-11-03 10:22:19 +01:00
|
|
|
parser.add_argument('-s', '--streams',
|
|
|
|
dest='streams',
|
|
|
|
type=str,
|
|
|
|
help='A comma-separated list of stream names.')
|
2017-08-07 22:26:52 +02:00
|
|
|
self.add_realm_args(parser, True)
|
2012-11-27 18:26:51 +01:00
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def handle(self, **options: str) -> None:
|
2017-08-07 22:26:52 +02:00
|
|
|
realm = self.get_realm(options)
|
|
|
|
if options["streams"] is None:
|
|
|
|
print("Please provide a default set of streams (which can be empty,\
|
|
|
|
with `--streams=`).", file=sys.stderr)
|
2012-11-27 18:26:51 +01:00
|
|
|
exit(1)
|
2017-08-07 22:26:52 +02:00
|
|
|
realm = self.get_realm(options)
|
2017-09-26 01:25:39 +02:00
|
|
|
assert realm is not None # Should be ensured by parser
|
2012-11-27 18:26:51 +01:00
|
|
|
|
2016-12-08 01:43:15 +01:00
|
|
|
stream_dict = {
|
|
|
|
stream.strip(): {"description": stream.strip(), "invite_only": False}
|
|
|
|
for stream in options["streams"].split(",")
|
2018-05-10 19:30:04 +02:00
|
|
|
} # type: Dict[str, Dict[str, Any]]
|
2017-08-07 22:26:52 +02:00
|
|
|
|
2016-12-08 01:43:15 +01:00
|
|
|
set_default_streams(realm, stream_dict)
|