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
|
2020-04-27 07:19:08 +02:00
|
|
|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
2019-10-05 02:35:07 +02:00
|
|
|
from django.db.migrations.state import StateApps
|
|
|
|
|
|
|
|
def update_role(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
|
|
|
|
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
|
2019-10-05 02:35:07 +02:00
|
|
|
user.save(update_fields=['role'])
|
|
|
|
|
|
|
|
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
|
|
|
|
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
|
|
|
|
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
|
|
|
|
user.save(update_fields=['is_guest'])
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
('zerver', '0247_realmauditlog_event_type_to_int'),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AddField(
|
|
|
|
model_name='userprofile',
|
|
|
|
name='role',
|
|
|
|
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
|
|
|
]
|