def handle(self, *args: Any, **options: Any) -> None:
        internal_bots = set([(bot['name'], bot['email_template'] % (settings.INTERNAL_BOT_DOMAIN,))
                            for bot in settings.REALM_INTERNAL_BOTS])

        existing_bots = list(UserProfile.objects.select_related(
            'realm').filter(email__in=[bot[1] for bot in internal_bots]))

        all_realms = list(Realm.objects.all())

        for realm in all_realms:
            this_realm_bots = set()
            for bot in existing_bots:
                if bot.realm.string_id == realm.string_id:
                    this_realm_bots.update([bot])
            bots_to_create = list(internal_bots - this_realm_bots)
            if bots_to_create:
                create_users(realm, bots_to_create, bot_type=UserProfile.DEFAULT_BOT)

        # Set the owners for these bots to the bots themselves
        bots = UserProfile.objects.filter(
            email__in=[bot_info[1] for bot_info in internal_bots],
            bot_owner__isnull=True
        )
        for bot in bots:
            bot.bot_owner = bot
            bot.save()

        self.stdout.write("Successfully created realm default bots.\n")
示例#2
0
def setup_realm_internal_bots(realm: Realm) -> None:
    internal_bots = [(bot['name'],
                      bot['email_template'] % (settings.INTERNAL_BOT_DOMAIN, ))
                     for bot in settings.REALM_INTERNAL_BOTS]
    create_users(realm, internal_bots, bot_type=UserProfile.DEFAULT_BOT)
    bots = UserProfile.objects.filter(
        realm=realm,
        email__in=[bot_info[1] for bot_info in internal_bots],
        bot_owner__isnull=True)
    for bot in bots:
        bot.bot_owner = bot
        bot.save()
示例#3
0
def setup_realm_internal_bots(realm: Realm) -> None:
    internal_bots = [(bot['name'], bot['email_template'] % (settings.INTERNAL_BOT_DOMAIN,))
                     for bot in settings.REALM_INTERNAL_BOTS]
    create_users(realm, internal_bots, bot_type=UserProfile.DEFAULT_BOT)
    bots = UserProfile.objects.filter(
        realm=realm,
        email__in=[bot_info[1] for bot_info in internal_bots],
        bot_owner__isnull=True
    )
    for bot in bots:
        bot.bot_owner = bot
        bot.save()
示例#4
0
def setup_realm_internal_bots(realm: Realm) -> None:
    """Create this realm's internal bots.

    This function is idempotent; it does nothing for a bot that
    already exists.
    """
    internal_bots = [(bot['name'], bot['email_template'] % (settings.INTERNAL_BOT_DOMAIN,))
                     for bot in settings.REALM_INTERNAL_BOTS]
    create_users(realm, internal_bots, bot_type=UserProfile.DEFAULT_BOT)
    bots = UserProfile.objects.filter(
        realm=realm,
        email__in=[bot_info[1] for bot_info in internal_bots],
        bot_owner__isnull=True
    )
    for bot in bots:
        bot.bot_owner = bot
        bot.save()
示例#5
0
def setup_realm_internal_bots(realm: Realm) -> None:
    """Create this realm's internal bots.

    This function is idempotent; it does nothing for a bot that
    already exists.
    """
    internal_bots = [(bot['name'], bot['email_template'] % (settings.INTERNAL_BOT_DOMAIN,))
                     for bot in settings.REALM_INTERNAL_BOTS]
    create_users(realm, internal_bots, bot_type=UserProfile.DEFAULT_BOT)
    bots = UserProfile.objects.filter(
        realm=realm,
        email__in=[bot_info[1] for bot_info in internal_bots],
        bot_owner__isnull=True
    )
    for bot in bots:
        bot.bot_owner = bot
        bot.save()