2013-11-04 16:54:15 +01:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
|
|
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
|
2013-11-14 16:59:10 +01:00
|
|
|
from zerver.lib.bulk_create import bulk_create_users
|
2013-11-14 16:06:12 +01:00
|
|
|
from zerver.lib.actions import set_default_streams, do_create_realm
|
2013-11-04 16:54:15 +01:00
|
|
|
|
|
|
|
from optparse import make_option
|
|
|
|
|
|
|
|
settings.TORNADO_SERVER = None
|
|
|
|
|
2013-11-14 16:59:10 +01:00
|
|
|
def create_users(name_list, bot=False):
|
|
|
|
realms = {}
|
|
|
|
for realm in Realm.objects.all():
|
|
|
|
realms[realm.domain] = realm
|
|
|
|
|
2013-11-04 16:54:15 +01:00
|
|
|
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)
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
2015-08-21 11:56:54 +02:00
|
|
|
help = "Populate an initial database for Zulip Voyager"
|
2013-11-04 16:54:15 +01:00
|
|
|
|
|
|
|
option_list = BaseCommand.option_list + (
|
|
|
|
make_option('--extra-users',
|
|
|
|
dest='extra_users',
|
|
|
|
type='int',
|
|
|
|
default=0,
|
|
|
|
help='The number of extra users to create'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def handle(self, **options):
|
2013-11-13 16:59:27 +01:00
|
|
|
Realm.objects.create(domain="zulip.com")
|
2013-11-04 16:54:15 +01:00
|
|
|
|
2013-11-13 16:59:27 +01:00
|
|
|
names = [(settings.FEEDBACK_BOT_NAME, settings.FEEDBACK_BOT)]
|
2013-11-14 16:59:10 +01:00
|
|
|
create_users(names, bot=True)
|
2013-11-04 16:54:15 +01:00
|
|
|
|
|
|
|
get_client("website")
|
|
|
|
get_client("API")
|
|
|
|
|
2013-11-14 16:59:10 +01:00
|
|
|
internal_bots = [(bot['name'], bot['email_template'] % (settings.INTERNAL_BOT_DOMAIN,))
|
|
|
|
for bot in settings.INTERNAL_BOTS]
|
|
|
|
create_users(internal_bots, bot=True)
|
2013-11-04 23:31:08 +01:00
|
|
|
# Set the owners for these bots to the bots themselves
|
2013-11-14 16:59:10 +01:00
|
|
|
bots = UserProfile.objects.filter(email__in=[bot_info[1] for bot_info in internal_bots])
|
2013-11-04 23:31:08 +01:00
|
|
|
for bot in bots:
|
|
|
|
bot.bot_owner = bot
|
|
|
|
bot.save()
|
2013-11-04 16:54:15 +01:00
|
|
|
|
2016-02-08 03:59:38 +01:00
|
|
|
# Initialize the email gateway bot as an API Super User
|
|
|
|
email_gateway_bot = UserProfile.objects.get(email__iexact=settings.EMAIL_GATEWAY_BOT)
|
|
|
|
email_gateway_bot.is_api_super_user = True
|
|
|
|
email_gateway_bot.save()
|
|
|
|
|
2013-11-14 16:59:10 +01:00
|
|
|
(admin_realm, _) = do_create_realm(settings.ADMIN_DOMAIN,
|
|
|
|
settings.ADMIN_DOMAIN, True)
|
|
|
|
|
2013-11-14 03:42:21 +01:00
|
|
|
set_default_streams(admin_realm, ["social", "engineering"])
|
|
|
|
|
2013-11-10 17:24:37 +01:00
|
|
|
self.stdout.write("Successfully populated database with initial data.\n")
|
2013-11-04 16:54:15 +01:00
|
|
|
|
|
|
|
site = Site.objects.get_current()
|
2013-11-13 22:33:43 +01:00
|
|
|
site.domain = settings.EXTERNAL_HOST
|
2013-11-04 16:54:15 +01:00
|
|
|
site.save()
|