From d474a41c036823070babea64f593d20a1bc21b91 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Wed, 8 May 2019 11:28:26 +0530 Subject: [PATCH] digest: Turn off digest_emails_enabled flag for realms by default. --- ...gle_realm_digest_emails_enabled_default.py | 28 +++++++++++++++++++ zerver/models.py | 2 +- zerver/tests/test_digest.py | 6 ++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 zerver/migrations/0219_toggle_realm_digest_emails_enabled_default.py diff --git a/zerver/migrations/0219_toggle_realm_digest_emails_enabled_default.py b/zerver/migrations/0219_toggle_realm_digest_emails_enabled_default.py new file mode 100644 index 0000000000..13817df7a5 --- /dev/null +++ b/zerver/migrations/0219_toggle_realm_digest_emails_enabled_default.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-05-08 05:42 +from __future__ import unicode_literals + +from django.db import migrations, models +from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor +from django.db.migrations.state import StateApps + +def disable_realm_digest_emails_enabled(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None: + Realm = apps.get_model("zerver", "Realm") + realms = Realm.objects.filter(digest_emails_enabled=True) + realms.update(digest_emails_enabled=False) + +class Migration(migrations.Migration): + + dependencies = [ + ('zerver', '0218_remove_create_stream_by_admins_only'), + ] + + operations = [ + migrations.AlterField( + model_name='realm', + name='digest_emails_enabled', + field=models.BooleanField(default=False), + ), + migrations.RunPython(disable_realm_digest_emails_enabled, + reverse_code=migrations.RunPython.noop) + ] diff --git a/zerver/models.py b/zerver/models.py index 76a4e92788..d1140e9b10 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -188,7 +188,7 @@ class Realm(models.Model): inline_url_embed_preview = models.BooleanField(default=True) # type: bool # Whether digest emails are enabled for the organization. - digest_emails_enabled = models.BooleanField(default=True) # type: bool + digest_emails_enabled = models.BooleanField(default=False) # type: bool # Day of the week on which the digest is sent (default: Tuesday). digest_weekday = models.SmallIntegerField(default=1) # type: int diff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.py index ab167898ef..fedd0f9a2e 100644 --- a/zerver/tests/test_digest.py +++ b/zerver/tests/test_digest.py @@ -76,6 +76,8 @@ class TestDigestEmailMessages(ZulipTestCase): @override_settings(SEND_DIGEST_EMAILS=True) def test_inactive_users_queued_for_digest(self, mock_django_timezone: mock.MagicMock, mock_queue_digest_recipient: mock.MagicMock) -> None: + # Turn on realm digest emails for all realms + Realm.objects.update(digest_emails_enabled=True) cutoff = timezone_now() # Test Tuesday mock_django_timezone.return_value = datetime.datetime(year=2016, month=1, day=5) @@ -113,6 +115,8 @@ class TestDigestEmailMessages(ZulipTestCase): @override_settings(SEND_DIGEST_EMAILS=True) def test_active_users_not_enqueued(self, mock_django_timezone: mock.MagicMock, mock_enough_traffic: mock.MagicMock) -> None: + # Turn on realm digest emails for all realms + Realm.objects.update(digest_emails_enabled=True) cutoff = timezone_now() # A Tuesday mock_django_timezone.return_value = datetime.datetime(year=2016, month=1, day=5) @@ -148,6 +152,8 @@ class TestDigestEmailMessages(ZulipTestCase): @override_settings(SEND_DIGEST_EMAILS=True) def test_no_email_digest_for_bots(self, mock_django_timezone: mock.MagicMock, mock_queue_digest_recipient: mock.MagicMock) -> None: + # Turn on realm digest emails for all realms + Realm.objects.update(digest_emails_enabled=True) cutoff = timezone_now() # A Tuesday mock_django_timezone.return_value = datetime.datetime(year=2016, month=1, day=5)