mirror of https://github.com/zulip/zulip.git
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:
parent
e2537ade44
commit
c24addf2d5
|
@ -6,26 +6,24 @@ from django.contrib.sites.models import Site
|
|||
from zerver.models import UserProfile, Stream, Recipient, \
|
||||
Subscription, Realm, get_client, email_to_username
|
||||
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 optparse import make_option
|
||||
|
||||
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()
|
||||
for full_name, email in name_list:
|
||||
short_name = email_to_username(email)
|
||||
user_set.add((email, full_name, short_name, True))
|
||||
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):
|
||||
help = "Populate an initial database for Zulip Enterprise"
|
||||
|
||||
|
@ -39,26 +37,25 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, **options):
|
||||
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)]
|
||||
create_users(realms, names, bot=True)
|
||||
create_users(names, bot=True)
|
||||
|
||||
get_client("website")
|
||||
get_client("API")
|
||||
|
||||
all_realm_bots = [(bot['name'], bot['email_template'] % (settings.ADMIN_DOMAIN,)) for bot in settings.REALM_BOTS]
|
||||
create_users(realms, all_realm_bots, bot=True)
|
||||
internal_bots = [(bot['name'], bot['email_template'] % (settings.INTERNAL_BOT_DOMAIN,))
|
||||
for bot in settings.INTERNAL_BOTS]
|
||||
create_users(internal_bots, bot=True)
|
||||
# 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:
|
||||
bot.bot_owner = bot
|
||||
bot.save()
|
||||
|
||||
(admin_realm, _) = do_create_realm(settings.ADMIN_DOMAIN,
|
||||
settings.ADMIN_DOMAIN, True)
|
||||
|
||||
set_default_streams(admin_realm, ["social", "engineering"])
|
||||
|
||||
self.stdout.write("Successfully populated database with initial data.\n")
|
||||
|
|
|
@ -206,7 +206,8 @@ class Command(BaseCommand):
|
|||
|
||||
# These bots are directly referenced from code and thus
|
||||
# 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 New User Bot", "new-user-bot@zulip.com"),
|
||||
("Zulip Error Bot", "error-bot@zulip.com"),
|
||||
|
|
|
@ -285,23 +285,25 @@ REQUIRED_SETTINGS = [("EXTERNAL_HOST", ""),
|
|||
("AUTHENTICATION_BACKENDS", ()),
|
||||
]
|
||||
|
||||
REALM_BOTS = [ {'var_name': 'NOTIFICATION_BOT',
|
||||
'email_template': 'notification-bot@%s',
|
||||
'name': 'Notification Bot'},
|
||||
{'var_name': 'EMAIL_GATEWAY_BOT',
|
||||
'email_template': 'emailgateway@%s',
|
||||
'name': 'Email Gateway'},
|
||||
{'var_name': 'NAGIOS_SEND_BOT',
|
||||
'email_template': 'nagios-send-bot@%s',
|
||||
'name': 'Nagios Send Bot'},
|
||||
{'var_name': 'NAGIOS_RECEIVE_BOT',
|
||||
'email_template': 'nagios-receive-bot@%s',
|
||||
'name': 'Nagios Receive Bot'} ]
|
||||
INTERNAL_BOTS = [ {'var_name': 'NOTIFICATION_BOT',
|
||||
'email_template': 'notification-bot@%s',
|
||||
'name': 'Notification Bot'},
|
||||
{'var_name': 'EMAIL_GATEWAY_BOT',
|
||||
'email_template': 'emailgateway@%s',
|
||||
'name': 'Email Gateway'},
|
||||
{'var_name': 'NAGIOS_SEND_BOT',
|
||||
'email_template': 'nagios-send-bot@%s',
|
||||
'name': 'Nagios Send Bot'},
|
||||
{'var_name': 'NAGIOS_RECEIVE_BOT',
|
||||
'email_template': 'nagios-receive-bot@%s',
|
||||
'name': 'Nagios Receive Bot'} ]
|
||||
|
||||
INTERNAL_BOT_DOMAIN = "zulip.com"
|
||||
|
||||
# Set the realm-specific bot names
|
||||
for bot in REALM_BOTS:
|
||||
for bot in INTERNAL_BOTS:
|
||||
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
|
||||
|
||||
if EMAIL_GATEWAY_BOT not in API_SUPER_USERS:
|
||||
|
|
Loading…
Reference in New Issue