2017-09-22 23:45:31 +02:00
|
|
|
|
2017-11-16 00:43:27 +01:00
|
|
|
from argparse import ArgumentParser
|
2018-02-13 16:13:04 +01:00
|
|
|
from typing import Any, List, Text
|
2017-09-22 23:45:31 +02:00
|
|
|
|
|
|
|
from confirmation.models import Confirmation, create_confirmation_link
|
2018-02-13 16:13:04 +01:00
|
|
|
from zerver.lib.actions import create_stream_if_needed, do_create_multiuse_invite_link
|
2017-11-16 00:43:27 +01:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2018-02-13 16:13:04 +01:00
|
|
|
from zerver.models import Stream
|
2017-09-22 23:45:31 +02:00
|
|
|
|
|
|
|
class Command(ZulipBaseCommand):
|
|
|
|
help = "Generates invite link that can be used for inviting multiple users"
|
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2017-09-22 23:45:31 +02:00
|
|
|
self.add_realm_args(parser, True)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
'-s', '--streams',
|
|
|
|
dest='streams',
|
|
|
|
type=str,
|
|
|
|
help='A comma-separated list of stream names.')
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
'--referred-by',
|
|
|
|
dest='referred_by',
|
|
|
|
type=str,
|
|
|
|
help='Email of referrer',
|
|
|
|
required=True,
|
|
|
|
)
|
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2017-09-22 23:45:31 +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
|
2017-09-22 23:45:31 +02:00
|
|
|
|
2018-02-13 16:13:04 +01:00
|
|
|
streams = [] # type: List[Stream]
|
2017-09-22 23:45:31 +02:00
|
|
|
if options["streams"]:
|
|
|
|
stream_names = set([stream.strip() for stream in options["streams"].split(",")])
|
|
|
|
for stream_name in set(stream_names):
|
|
|
|
stream, _ = create_stream_if_needed(realm, stream_name)
|
|
|
|
streams.append(stream)
|
|
|
|
|
|
|
|
referred_by = self.get_user(options['referred_by'], realm)
|
2018-02-13 16:13:04 +01:00
|
|
|
invite_link = do_create_multiuse_invite_link(referred_by, streams)
|
2017-09-22 23:45:31 +02:00
|
|
|
print("You can use %s to invite as many number of people to the organization." % (invite_link,))
|