Files
zulip/zerver/migrations/0242_fix_bot_email_property.py
Tim Abbott 8024b1179a bots: Fix bot email addresses with EMAIL_ADDRESS_VISIBILITY_ADMINS.
When using our EMAIL_ADDRESS_VISIBILITY_ADMINS feature, we were
apparently creating bot users with different email and delivery_email
properties, due to effectively an oversight in how the code was
written (the initial migration handled bots correctly, but not bots
created after the transition).

Following the refactor in the last commit, the fix for this is just
adding the missing conditional, a test, and a database migration to
fix any incorrectly created bots leaked previously.
2019-09-23 15:53:53 -07:00

26 lines
954 B
Python

# -*- coding: utf-8 -*-
# Generated by Django 1.11.24 on 2019-09-23 20:39
from __future__ import unicode_literals
from django.db import migrations
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
def fix_bot_email_property(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
UserProfile = apps.get_model('zerver', 'UserProfile')
for user_profile in UserProfile.objects.filter(is_bot=True):
if user_profile.email != user_profile.delivery_email:
user_profile.email = user_profile.delivery_email
user_profile.save(update_fields=["email"])
class Migration(migrations.Migration):
dependencies = [
('zerver', '0241_usermessage_bigint_id_migration_finalize'),
]
operations = [
migrations.RunPython(fix_bot_email_property,
reverse_code=migrations.RunPython.noop),
]