2017-02-15 04:35:10 +01:00
|
|
|
# Generated by Django 1.10.5 on 2017-03-04 07:33
|
2017-11-16 00:44:00 +01:00
|
|
|
import django.db.models.deletion
|
2017-02-15 04:35:10 +01:00
|
|
|
from django.conf import settings
|
|
|
|
from django.db import migrations, models
|
2020-04-27 07:19:08 +02:00
|
|
|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
2017-11-16 00:44:00 +01:00
|
|
|
from django.db.migrations.state import StateApps
|
2017-04-15 04:03:56 +02:00
|
|
|
from django.utils.timezone import now as timezone_now
|
2017-02-15 04:35:10 +01:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2017-10-26 11:36:30 +02:00
|
|
|
def backfill_user_activations_and_deactivations(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
|
2017-04-15 04:03:56 +02:00
|
|
|
migration_time = timezone_now()
|
2017-03-05 02:23:10 +01:00
|
|
|
RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog')
|
|
|
|
UserProfile = apps.get_model('zerver', 'UserProfile')
|
2017-02-15 04:35:10 +01:00
|
|
|
|
|
|
|
for user in UserProfile.objects.all():
|
|
|
|
RealmAuditLog.objects.create(realm=user.realm, modified_user=user,
|
|
|
|
event_type='user_created', event_time=user.date_joined,
|
|
|
|
backfilled=False)
|
|
|
|
|
|
|
|
for user in UserProfile.objects.filter(is_active=False):
|
|
|
|
RealmAuditLog.objects.create(realm=user.realm, modified_user=user,
|
|
|
|
event_type='user_deactivated', event_time=migration_time,
|
|
|
|
backfilled=True)
|
|
|
|
|
2017-10-26 11:36:30 +02:00
|
|
|
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
|
2017-03-05 02:23:10 +01:00
|
|
|
RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog')
|
2017-02-15 04:35:10 +01:00
|
|
|
RealmAuditLog.objects.filter(event_type='user_created').delete()
|
|
|
|
RealmAuditLog.objects.filter(event_type='user_deactivated').delete()
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
('zerver', '0056_userprofile_emoji_alt_code'),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.CreateModel(
|
|
|
|
name='RealmAuditLog',
|
|
|
|
fields=[
|
|
|
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
|
|
('event_type', models.CharField(max_length=40)),
|
|
|
|
('backfilled', models.BooleanField(default=False)),
|
|
|
|
('event_time', models.DateTimeField()),
|
|
|
|
('acting_user', models.ForeignKey(null=True,
|
|
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
|
|
related_name='+',
|
|
|
|
to=settings.AUTH_USER_MODEL)),
|
|
|
|
('modified_stream', models.ForeignKey(null=True,
|
|
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
|
|
to='zerver.Stream')),
|
|
|
|
('modified_user', models.ForeignKey(null=True,
|
|
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
|
|
related_name='+',
|
|
|
|
to=settings.AUTH_USER_MODEL)),
|
|
|
|
('realm', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='zerver.Realm')),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
|
|
|
|
migrations.RunPython(backfill_user_activations_and_deactivations,
|
2020-04-29 08:43:25 +02:00
|
|
|
reverse_code=reverse_code, elidable=True),
|
2017-02-15 04:35:10 +01:00
|
|
|
|
|
|
|
]
|