2020-06-17 00:37:24 +02:00
|
|
|
# Generated by Django 1.11.26 on 2020-06-16 22:26
|
|
|
|
|
|
|
|
from django.db import migrations
|
2020-12-13 17:14:42 +01:00
|
|
|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
2020-06-17 00:37:24 +02:00
|
|
|
from django.db.migrations.state import StateApps
|
|
|
|
|
|
|
|
|
|
|
|
def clear_preregistrationuser_invited_as_admin(
|
2021-02-12 08:19:30 +01:00
|
|
|
apps: StateApps, schema_editor: DatabaseSchemaEditor
|
|
|
|
) -> None:
|
2020-06-17 00:37:24 +02:00
|
|
|
"""This migration fixes any PreregistrationUser objects that might
|
|
|
|
have been already corrupted to have the administrator role by the
|
|
|
|
buggy original version of migration
|
|
|
|
0198_preregistrationuser_invited_as.
|
|
|
|
|
|
|
|
Since invitations that create new users as administrators are
|
|
|
|
rare, it is cleaner to just remove the role from all
|
|
|
|
PreregistrationUser objects than to filter for just those older
|
|
|
|
invitation objects that could have been corrupted by the original
|
|
|
|
migration, which would have been possible using the
|
|
|
|
django_migrations table to check the date when the buggy migration
|
|
|
|
was run.
|
|
|
|
"""
|
|
|
|
INVITED_AS_MEMBER = 1
|
|
|
|
INVITED_AS_REALM_ADMIN = 2
|
|
|
|
PreregistrationUser = apps.get_model("zerver", "PreregistrationUser")
|
2021-02-12 08:19:30 +01:00
|
|
|
PreregistrationUser.objects.filter(invited_as=INVITED_AS_REALM_ADMIN).update(
|
|
|
|
invited_as=INVITED_AS_MEMBER
|
|
|
|
)
|
|
|
|
|
2020-06-17 00:37:24 +02:00
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2021-02-12 08:20:45 +01:00
|
|
|
("zerver", "0260_missed_message_addresses_from_redis_to_db"),
|
2020-06-17 00:37:24 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.RunPython(
|
2021-02-12 08:19:30 +01:00
|
|
|
clear_preregistrationuser_invited_as_admin, reverse_code=migrations.RunPython.noop
|
2020-06-17 00:37:24 +02:00
|
|
|
),
|
|
|
|
]
|