Files
zulip/zerver/migrations/0248_userprofile_role_start.py
Anders Kaseorg 365fe0b3d5 python: Sort imports with isort.
Fixes #2665.

Regenerated by tabbott with `lint --fix` after a rebase and change in
parameters.

Note from tabbott: In a few cases, this converts technical debt in the
form of unsorted imports into different technical debt in the form of
our largest files having very long, ugly import sequences at the
start.  I expect this change will increase pressure for us to split
those files, which isn't a bad thing.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-11 16:45:32 -07:00

49 lines
1.7 KiB
Python

# Generated by Django 1.11.24 on 2019-10-03 22:27
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
def update_role(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
UserProfile = apps.get_model('zerver', 'UserProfile')
# The values at the time of this migration
UserProfile.ROLE_REALM_ADMINISTRATOR = 200
UserProfile.ROLE_MEMBER = 400
UserProfile.ROLE_GUEST = 600
for user in UserProfile.objects.all():
if user.is_realm_admin:
user.role = UserProfile.ROLE_REALM_ADMINISTRATOR
elif user.is_guest:
user.role = UserProfile.ROLE_GUEST
else:
user.role = UserProfile.ROLE_MEMBER
user.save(update_fields=['role'])
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
UserProfile = apps.get_model('zerver', 'UserProfile')
UserProfile.ROLE_REALM_ADMINISTRATOR = 200
UserProfile.ROLE_GUEST = 600
for user in UserProfile.objects.all():
if user.role == UserProfile.ROLE_REALM_ADMINISTRATOR:
user.is_realm_admin = True
user.save(update_fields=['is_realm_admin'])
elif user.role == UserProfile.ROLE_GUEST:
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),
),
migrations.RunPython(update_role, reverse_code=reverse_code, elidable=True),
]