2016-06-17 18:49:36 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.db import models, migrations
|
2016-06-29 01:32:57 +02:00
|
|
|
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
|
|
|
|
from django.db.migrations.state import StateApps
|
2016-06-17 18:49:36 +02:00
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
def migrate_existing_data(apps, schema_editor):
|
2016-06-29 01:32:57 +02:00
|
|
|
# type: (StateApps, DatabaseSchemaEditor) -> None
|
2016-06-17 18:49:36 +02:00
|
|
|
Attachment = apps.get_model('zerver', 'Attachment')
|
2017-03-05 02:29:08 +01:00
|
|
|
Recipient = apps.get_model('zerver', 'Recipient')
|
2016-06-17 18:49:36 +02:00
|
|
|
Stream = apps.get_model('zerver', 'Stream')
|
|
|
|
|
|
|
|
attachments = Attachment.objects.all()
|
|
|
|
for entry in attachments:
|
|
|
|
owner = entry.owner
|
|
|
|
entry.realm = owner.realm
|
|
|
|
for message in entry.messages.all():
|
|
|
|
if owner == message.sender:
|
|
|
|
if message.recipient.type == Recipient.STREAM:
|
|
|
|
stream = Stream.objects.get(id=message.recipient.type_id)
|
|
|
|
is_realm_public = stream.realm.domain != "mit.edu" and not stream.invite_only
|
|
|
|
entry.is_realm_public = entry.is_realm_public or is_realm_public
|
|
|
|
|
|
|
|
entry.save()
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
('zerver', '0020_add_tracking_attachment'),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.RunPython(migrate_existing_data)
|
|
|
|
]
|