2017-11-16 00:43:27 +01:00
|
|
|
from argparse import ArgumentParser
|
2018-05-10 19:30:04 +02:00
|
|
|
from typing import Any, List
|
2017-09-22 23:45:31 +02:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
from zerver.lib.actions import do_create_multiuse_invite_link, ensure_stream
|
2017-11-16 00:43:27 +01:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2020-01-14 21:59:46 +01:00
|
|
|
from zerver.models import PreregistrationUser, 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
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
streams: List[Stream] = []
|
2017-09-22 23:45:31 +02:00
|
|
|
if options["streams"]:
|
2020-04-09 21:51:58 +02:00
|
|
|
stream_names = {stream.strip() for stream in options["streams"].split(",")}
|
2017-09-22 23:45:31 +02:00
|
|
|
for stream_name in set(stream_names):
|
2018-03-21 22:05:21 +01:00
|
|
|
stream = ensure_stream(realm, stream_name)
|
2017-09-22 23:45:31 +02:00
|
|
|
streams.append(stream)
|
|
|
|
|
|
|
|
referred_by = self.get_user(options['referred_by'], realm)
|
2019-02-06 22:57:14 +01:00
|
|
|
invite_as = PreregistrationUser.INVITE_AS['MEMBER']
|
|
|
|
invite_link = do_create_multiuse_invite_link(referred_by, invite_as, streams)
|
2020-06-10 06:41:04 +02:00
|
|
|
print(f"You can use {invite_link} to invite as many number of people to the organization.")
|