Build internal bots in the zulip.com domain.

Otherwise do_create_realm can't actually send the notifications.

(imported from commit 4fa9a53f1d3d8a2e26d7b89401e7dfa77f2f7533)
This commit is contained in:
Tim Abbott 2013-11-14 10:59:10 -05:00
parent e2537ade44
commit c24addf2d5
3 changed files with 32 additions and 32 deletions

View File

@ -6,26 +6,24 @@ from django.contrib.sites.models import Site
from zerver.models import UserProfile, Stream, Recipient, \ from zerver.models import UserProfile, Stream, Recipient, \
Subscription, Realm, get_client, email_to_username Subscription, Realm, get_client, email_to_username
from django.conf import settings from django.conf import settings
from zerver.lib.bulk_create import bulk_create_streams, bulk_create_users from zerver.lib.bulk_create import bulk_create_users
from zerver.lib.actions import set_default_streams, do_create_realm from zerver.lib.actions import set_default_streams, do_create_realm
from optparse import make_option from optparse import make_option
settings.TORNADO_SERVER = None settings.TORNADO_SERVER = None
def create_users(realms, name_list, bot=False): def create_users(name_list, bot=False):
realms = {}
for realm in Realm.objects.all():
realms[realm.domain] = realm
user_set = set() user_set = set()
for full_name, email in name_list: for full_name, email in name_list:
short_name = email_to_username(email) short_name = email_to_username(email)
user_set.add((email, full_name, short_name, True)) user_set.add((email, full_name, short_name, True))
bulk_create_users(realms, user_set, bot) bulk_create_users(realms, user_set, bot)
def create_streams(realms, realm, stream_list):
stream_set = set()
for stream_name in stream_list:
stream_set.add((realm.domain, stream_name))
bulk_create_streams(realms, stream_set)
class Command(BaseCommand): class Command(BaseCommand):
help = "Populate an initial database for Zulip Enterprise" help = "Populate an initial database for Zulip Enterprise"
@ -39,26 +37,25 @@ class Command(BaseCommand):
def handle(self, **options): def handle(self, **options):
Realm.objects.create(domain="zulip.com") Realm.objects.create(domain="zulip.com")
(admin_realm, _) = do_create_realm(settings.ADMIN_DOMAIN,
settings.ADMIN_DOMAIN, True)
realms = {}
for realm in Realm.objects.all():
realms[realm.domain] = realm
names = [(settings.FEEDBACK_BOT_NAME, settings.FEEDBACK_BOT)] names = [(settings.FEEDBACK_BOT_NAME, settings.FEEDBACK_BOT)]
create_users(realms, names, bot=True) create_users(names, bot=True)
get_client("website") get_client("website")
get_client("API") get_client("API")
all_realm_bots = [(bot['name'], bot['email_template'] % (settings.ADMIN_DOMAIN,)) for bot in settings.REALM_BOTS] internal_bots = [(bot['name'], bot['email_template'] % (settings.INTERNAL_BOT_DOMAIN,))
create_users(realms, all_realm_bots, bot=True) for bot in settings.INTERNAL_BOTS]
create_users(internal_bots, bot=True)
# Set the owners for these bots to the bots themselves # Set the owners for these bots to the bots themselves
bots = UserProfile.objects.filter(email__in=[bot_info[1] for bot_info in all_realm_bots]) bots = UserProfile.objects.filter(email__in=[bot_info[1] for bot_info in internal_bots])
for bot in bots: for bot in bots:
bot.bot_owner = bot bot.bot_owner = bot
bot.save() bot.save()
(admin_realm, _) = do_create_realm(settings.ADMIN_DOMAIN,
settings.ADMIN_DOMAIN, True)
set_default_streams(admin_realm, ["social", "engineering"]) set_default_streams(admin_realm, ["social", "engineering"])
self.stdout.write("Successfully populated database with initial data.\n") self.stdout.write("Successfully populated database with initial data.\n")

View File

@ -206,7 +206,8 @@ class Command(BaseCommand):
# These bots are directly referenced from code and thus # These bots are directly referenced from code and thus
# are needed for the test suite. # are needed for the test suite.
all_realm_bots = [(bot['name'], bot['email_template'] % (settings.ADMIN_DOMAIN,)) for bot in settings.REALM_BOTS] all_realm_bots = [(bot['name'], bot['email_template'] % (settings.INTERNAL_BOT_DOMAIN,))
for bot in settings.INTERNAL_BOTS]
zulip_realm_bots = [ zulip_realm_bots = [
("Zulip New User Bot", "new-user-bot@zulip.com"), ("Zulip New User Bot", "new-user-bot@zulip.com"),
("Zulip Error Bot", "error-bot@zulip.com"), ("Zulip Error Bot", "error-bot@zulip.com"),

View File

@ -285,7 +285,7 @@ REQUIRED_SETTINGS = [("EXTERNAL_HOST", ""),
("AUTHENTICATION_BACKENDS", ()), ("AUTHENTICATION_BACKENDS", ()),
] ]
REALM_BOTS = [ {'var_name': 'NOTIFICATION_BOT', INTERNAL_BOTS = [ {'var_name': 'NOTIFICATION_BOT',
'email_template': 'notification-bot@%s', 'email_template': 'notification-bot@%s',
'name': 'Notification Bot'}, 'name': 'Notification Bot'},
{'var_name': 'EMAIL_GATEWAY_BOT', {'var_name': 'EMAIL_GATEWAY_BOT',
@ -298,10 +298,12 @@ REALM_BOTS = [ {'var_name': 'NOTIFICATION_BOT',
'email_template': 'nagios-receive-bot@%s', 'email_template': 'nagios-receive-bot@%s',
'name': 'Nagios Receive Bot'} ] 'name': 'Nagios Receive Bot'} ]
INTERNAL_BOT_DOMAIN = "zulip.com"
# Set the realm-specific bot names # Set the realm-specific bot names
for bot in REALM_BOTS: for bot in INTERNAL_BOTS:
if not bot['var_name'] in vars(): if not bot['var_name'] in vars():
bot_email = bot['email_template'] % (ADMIN_DOMAIN,) bot_email = bot['email_template'] % (INTERNAL_BOT_DOMAIN,)
vars()[bot['var_name'] ] = bot_email vars()[bot['var_name'] ] = bot_email
if EMAIL_GATEWAY_BOT not in API_SUPER_USERS: if EMAIL_GATEWAY_BOT not in API_SUPER_USERS: