mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Issue #2088 asked for a wrapper to be created for `create_stream_if_needed` (called `ensure_stream`) for the 25 times that `create_stream_if_needed` is called and ignores whether the stream was created. This commit replaces relevant occurences of `create_stream_if_needed` with `ensure_stream`, including imports. The changes weren't significant enough to add any tests or do any additional manual testing. The refactoring intended to make the API easier to use in most cases. The majority of uses of `create_stream_if_needed` ignored the second parameter. Fixes: #2088.
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
 | 
						|
from argparse import ArgumentParser
 | 
						|
from typing import Any, List, Text
 | 
						|
 | 
						|
from confirmation.models import Confirmation, create_confirmation_link
 | 
						|
from zerver.lib.actions import ensure_stream, do_create_multiuse_invite_link
 | 
						|
from zerver.lib.management import ZulipBaseCommand
 | 
						|
from zerver.models import Stream
 | 
						|
 | 
						|
class Command(ZulipBaseCommand):
 | 
						|
    help = "Generates invite link that can be used for inviting multiple users"
 | 
						|
 | 
						|
    def add_arguments(self, parser: ArgumentParser) -> None:
 | 
						|
        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,
 | 
						|
        )
 | 
						|
 | 
						|
    def handle(self, *args: Any, **options: Any) -> None:
 | 
						|
        realm = self.get_realm(options)
 | 
						|
        assert realm is not None  # Should be ensured by parser
 | 
						|
 | 
						|
        streams = []  # type: List[Stream]
 | 
						|
        if options["streams"]:
 | 
						|
            stream_names = set([stream.strip() for stream in options["streams"].split(",")])
 | 
						|
            for stream_name in set(stream_names):
 | 
						|
                stream = ensure_stream(realm, stream_name)
 | 
						|
                streams.append(stream)
 | 
						|
 | 
						|
        referred_by = self.get_user(options['referred_by'], realm)
 | 
						|
        invite_link = do_create_multiuse_invite_link(referred_by, streams)
 | 
						|
        print("You can use %s to invite as many number of people to the organization." % (invite_link,))
 |