2019-02-13 10:22:16 +01:00
|
|
|
# Generated by Django 1.11.18 on 2019-02-13 20:13
|
|
|
|
|
|
|
|
from django.db import migrations
|
2022-05-27 23:33:51 +02:00
|
|
|
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
|
2019-02-13 10:22:16 +01:00
|
|
|
from django.db.migrations.state import StateApps
|
|
|
|
|
|
|
|
RECIPIENT_STREAM = 2
|
|
|
|
SETTINGS_MAP = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"desktop_notifications": "enable_stream_desktop_notifications",
|
|
|
|
"audible_notifications": "enable_stream_sounds",
|
|
|
|
"push_notifications": "enable_stream_push_notifications",
|
|
|
|
"email_notifications": "enable_stream_email_notifications",
|
2019-02-13 10:22:16 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2022-05-27 23:33:51 +02:00
|
|
|
def update_notification_settings(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
Subscription = apps.get_model("zerver", "Subscription")
|
|
|
|
UserProfile = apps.get_model("zerver", "UserProfile")
|
2019-02-13 10:22:16 +01:00
|
|
|
|
|
|
|
for setting_value in [True, False]:
|
|
|
|
for sub_setting_name, user_setting_name in SETTINGS_MAP.items():
|
|
|
|
sub_filter_kwargs = {sub_setting_name: setting_value}
|
|
|
|
user_filter_kwargs = {user_setting_name: setting_value}
|
|
|
|
update_kwargs = {sub_setting_name: None}
|
2021-02-12 08:19:30 +01:00
|
|
|
Subscription.objects.filter(
|
|
|
|
user_profile__in=UserProfile.objects.filter(**user_filter_kwargs),
|
|
|
|
recipient__type=RECIPIENT_STREAM,
|
|
|
|
**sub_filter_kwargs,
|
|
|
|
).update(**update_kwargs)
|
|
|
|
|
2019-02-13 10:22:16 +01:00
|
|
|
|
2022-05-27 23:33:51 +02:00
|
|
|
def reverse_notification_settings(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
Subscription = apps.get_model("zerver", "Subscription")
|
|
|
|
UserProfile = apps.get_model("zerver", "UserProfile")
|
2019-02-13 10:22:16 +01:00
|
|
|
|
|
|
|
for setting_value in [True, False]:
|
|
|
|
for sub_setting_name, user_setting_name in SETTINGS_MAP.items():
|
|
|
|
sub_filter_kwargs = {sub_setting_name: None}
|
|
|
|
user_filter_kwargs = {user_setting_name: setting_value}
|
|
|
|
update_kwargs = {sub_setting_name: setting_value}
|
2021-02-12 08:19:30 +01:00
|
|
|
Subscription.objects.filter(
|
|
|
|
user_profile__in=UserProfile.objects.filter(**user_filter_kwargs),
|
|
|
|
recipient__type=RECIPIENT_STREAM,
|
|
|
|
**sub_filter_kwargs,
|
|
|
|
).update(**update_kwargs)
|
2019-02-13 10:22:16 +01:00
|
|
|
|
|
|
|
for sub_setting_name, user_setting_name in SETTINGS_MAP.items():
|
|
|
|
sub_filter_kwargs = {sub_setting_name: None}
|
|
|
|
update_kwargs = {sub_setting_name: True}
|
2021-02-12 08:19:30 +01:00
|
|
|
Subscription.objects.filter(recipient__type__in=[1, 3], **sub_filter_kwargs).update(
|
|
|
|
**update_kwargs
|
|
|
|
)
|
|
|
|
|
2019-02-13 10:22:16 +01:00
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2021-02-12 08:20:45 +01:00
|
|
|
("zerver", "0220_subscription_notification_settings"),
|
2019-02-13 10:22:16 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
2021-02-12 08:19:30 +01:00
|
|
|
migrations.RunPython(
|
|
|
|
update_notification_settings, reverse_notification_settings, elidable=True
|
|
|
|
),
|
2019-02-13 10:22:16 +01:00
|
|
|
]
|