2019-10-05 02:35:07 +02:00
|
|
|
# Generated by Django 1.11.24 on 2019-10-03 22:27
|
|
|
|
from django.db import migrations, models
|
2023-03-04 01:40:40 +01:00
|
|
|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
2019-10-05 02:35:07 +02:00
|
|
|
from django.db.migrations.state import StateApps
|
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2022-05-27 23:33:51 +02:00
|
|
|
def update_role(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
UserProfile = apps.get_model("zerver", "UserProfile")
|
2020-02-17 17:13:57 +01:00
|
|
|
# The values at the time of this migration
|
|
|
|
UserProfile.ROLE_REALM_ADMINISTRATOR = 200
|
|
|
|
UserProfile.ROLE_MEMBER = 400
|
|
|
|
UserProfile.ROLE_GUEST = 600
|
2019-10-05 02:35:07 +02:00
|
|
|
for user in UserProfile.objects.all():
|
|
|
|
if user.is_realm_admin:
|
2020-02-17 17:13:57 +01:00
|
|
|
user.role = UserProfile.ROLE_REALM_ADMINISTRATOR
|
2019-10-05 02:35:07 +02:00
|
|
|
elif user.is_guest:
|
2020-02-17 17:13:57 +01:00
|
|
|
user.role = UserProfile.ROLE_GUEST
|
2019-10-05 02:35:07 +02:00
|
|
|
else:
|
2020-02-17 17:13:57 +01:00
|
|
|
user.role = UserProfile.ROLE_MEMBER
|
2021-02-12 08:20:45 +01:00
|
|
|
user.save(update_fields=["role"])
|
2019-10-05 02:35:07 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2022-05-27 23:33:51 +02:00
|
|
|
def reverse_code(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
UserProfile = apps.get_model("zerver", "UserProfile")
|
2020-02-17 17:13:57 +01:00
|
|
|
UserProfile.ROLE_REALM_ADMINISTRATOR = 200
|
|
|
|
UserProfile.ROLE_GUEST = 600
|
2019-10-05 02:35:07 +02:00
|
|
|
for user in UserProfile.objects.all():
|
2020-02-17 17:13:57 +01:00
|
|
|
if user.role == UserProfile.ROLE_REALM_ADMINISTRATOR:
|
2019-10-05 02:35:07 +02:00
|
|
|
user.is_realm_admin = True
|
2021-02-12 08:20:45 +01:00
|
|
|
user.save(update_fields=["is_realm_admin"])
|
2020-02-17 17:13:57 +01:00
|
|
|
elif user.role == UserProfile.ROLE_GUEST:
|
2019-10-05 02:35:07 +02:00
|
|
|
user.is_guest = True
|
2021-02-12 08:20:45 +01:00
|
|
|
user.save(update_fields=["is_guest"])
|
2019-10-05 02:35:07 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-10-05 02:35:07 +02:00
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
2021-02-12 08:20:45 +01:00
|
|
|
("zerver", "0247_realmauditlog_event_type_to_int"),
|
2019-10-05 02:35:07 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AddField(
|
2021-02-12 08:20:45 +01:00
|
|
|
model_name="userprofile",
|
|
|
|
name="role",
|
2019-10-05 02:35:07 +02:00
|
|
|
field=models.PositiveSmallIntegerField(null=True),
|
|
|
|
),
|
2020-04-29 08:43:25 +02:00
|
|
|
migrations.RunPython(update_role, reverse_code=reverse_code, elidable=True),
|
2019-10-05 02:35:07 +02:00
|
|
|
]
|