mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	We extract the entire operations of the management command to a function create_if_missing_realm_internal_bots in the zerver/lib/onboarding.py. The logic for determining if there are any realm internal bots which have not been created is extracted to a function missing_any_realm_internal_bots in actions.py.
		
			
				
	
	
		
			23 lines
		
	
	
		
			752 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			752 B
		
	
	
	
		
			Python
		
	
	
	
	
	
 | 
						|
from typing import Any, Iterable, Tuple
 | 
						|
 | 
						|
from django.conf import settings
 | 
						|
from django.core.management.base import BaseCommand
 | 
						|
from django.db.models import Count
 | 
						|
 | 
						|
from zerver.lib.onboarding import create_if_missing_realm_internal_bots
 | 
						|
from zerver.models import Realm, UserProfile
 | 
						|
 | 
						|
class Command(BaseCommand):
 | 
						|
    help = """\
 | 
						|
Create realm internal bots if absent, in all realms.
 | 
						|
 | 
						|
These are normally created when the realm is, so this should be a no-op
 | 
						|
except when upgrading to a version that adds a new realm internal bot.
 | 
						|
"""
 | 
						|
 | 
						|
    def handle(self, *args: Any, **options: Any) -> None:
 | 
						|
        create_if_missing_realm_internal_bots()
 | 
						|
        # create_users is idempotent -- it's a no-op when a given email
 | 
						|
        # already has a user in a given realm.
 |