commands: Add 'skip-delay' option to send_zulip_update_announcements.

This commit adds a 'skip-delay' option to the
'send_zulip_update_announcements' management command.

It will be useful for self-hosted servers after 9.0 upgrade to
avoid the 24 hour delay to receive update messages after group
DM is sent to the admins.

One can run the management command with the --skip-delay flag
to immediately send the update messages.
This commit is contained in:
Prakhar Pratyush 2024-04-09 20:49:32 +05:30 committed by Tim Abbott
parent 30273403ea
commit bc0325922e
4 changed files with 73 additions and 13 deletions

View File

@ -13,7 +13,15 @@ log][commit-log] for an up-to-date list of all changes.
#### Upgrade notes for 9.0
- None yet.
- This release introduces a new [Zulip updates](https://zulip.com/help/configure-automated-notices#zulip-update-announcements) feature, which
announces significant product changes and new features via automated
messages to a configurable stream. Generally, these announcements will
be sent automatically when upgrading to the new release. However, when
you first upgrade to the 9.x series, they will be sent with a delay
(explained in an automated direct message to organization administrators)
to give time to potentially reconfigure which stream to use. You can
override the delay by running `./manage.py send_zulip_update_announcements --skip-delay`
once you've done any necessary configuration updates.
## Zulip Server 8.x series

View File

@ -182,7 +182,7 @@ def send_messages_and_update_level(
realm.save(update_fields=["zulip_update_announcements_level"])
def send_zulip_update_announcements() -> None:
def send_zulip_update_announcements(skip_delay: bool) -> None:
latest_zulip_update_announcements_level = get_latest_zulip_update_announcements_level()
realms = get_realms_behind_zulip_update_announcements_level(
@ -220,6 +220,7 @@ def send_zulip_update_announcements() -> None:
if (
realm_zulip_update_announcements_level == 0
and is_group_direct_message_sent_to_admins_within_days(realm, days=1)
and not skip_delay
):
continue

View File

@ -1,3 +1,4 @@
from argparse import ArgumentParser
from typing import Any
from typing_extensions import override
@ -10,5 +11,13 @@ class Command(ZulipBaseCommand):
help = """Script to send zulip update announcements to realms."""
@override
def handle(self, *args: Any, **options: str) -> None:
send_zulip_update_announcements()
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument(
"--skip-delay",
action="store_true",
help="Immediately send updates if 'zulip_update_announcements_stream' is configured.",
)
@override
def handle(self, *args: Any, **options: Any) -> None:
send_zulip_update_announcements(skip_delay=options["skip_delay"])

View File

@ -64,7 +64,7 @@ class ZulipUpdateAnnouncementsTest(ZulipTestCase):
now = timezone_now()
with time_machine.travel(now, tick=False):
send_zulip_update_announcements()
send_zulip_update_announcements(skip_delay=False)
realm.refresh_from_db()
group_direct_message = group_direct_messages.first()
@ -83,12 +83,12 @@ class ZulipUpdateAnnouncementsTest(ZulipTestCase):
# Wait for one week before starting to skip sending updates.
with time_machine.travel(now + timedelta(days=2), tick=False):
send_zulip_update_announcements()
send_zulip_update_announcements(skip_delay=False)
realm.refresh_from_db()
self.assertEqual(realm.zulip_update_announcements_level, 0)
with time_machine.travel(now + timedelta(days=8), tick=False):
send_zulip_update_announcements()
send_zulip_update_announcements(skip_delay=False)
realm.refresh_from_db()
self.assertEqual(realm.zulip_update_announcements_level, 2)
@ -110,7 +110,7 @@ class ZulipUpdateAnnouncementsTest(ZulipTestCase):
# verify zulip update announcements sent to configured stream.
with time_machine.travel(now + timedelta(days=10), tick=False):
send_zulip_update_announcements()
send_zulip_update_announcements(skip_delay=False)
realm.refresh_from_db()
stream_messages = Message.objects.filter(
realm=realm,
@ -148,7 +148,7 @@ class ZulipUpdateAnnouncementsTest(ZulipTestCase):
now = timezone_now()
with time_machine.travel(now, tick=False):
send_zulip_update_announcements()
send_zulip_update_announcements(skip_delay=False)
realm.refresh_from_db()
self.assertTrue(group_direct_messages.exists())
@ -156,12 +156,12 @@ class ZulipUpdateAnnouncementsTest(ZulipTestCase):
# Wait for 24 hours before starting to send updates.
with time_machine.travel(now + timedelta(hours=10), tick=False):
send_zulip_update_announcements()
send_zulip_update_announcements(skip_delay=False)
realm.refresh_from_db()
self.assertEqual(realm.zulip_update_announcements_level, 0)
with time_machine.travel(now + timedelta(days=1), tick=False):
send_zulip_update_announcements()
send_zulip_update_announcements(skip_delay=False)
realm.refresh_from_db()
self.assertEqual(realm.zulip_update_announcements_level, 2)
@ -180,7 +180,7 @@ class ZulipUpdateAnnouncementsTest(ZulipTestCase):
# verify zulip update announcements sent to configured stream.
with time_machine.travel(now + timedelta(days=2), tick=False):
send_zulip_update_announcements()
send_zulip_update_announcements(skip_delay=False)
realm.refresh_from_db()
notification_bot = get_system_bot(settings.NOTIFICATION_BOT, realm.id)
stream_messages = Message.objects.filter(
@ -194,6 +194,48 @@ class ZulipUpdateAnnouncementsTest(ZulipTestCase):
self.assertEqual(stream_messages[1].content, "Announcement message 4.")
self.assertEqual(realm.zulip_update_announcements_level, 4)
def test_send_zulip_update_announcements_skip_delay(self) -> None:
with mock.patch(
"zerver.lib.zulip_update_announcements.zulip_update_announcements",
self.zulip_update_announcements,
):
realm = get_realm("zulip")
# realm predates the "zulip updates" feature with the
# zulip_update_announcements_stream configured.
realm.zulip_update_announcements_level = None
realm.zulip_update_announcements_stream = get_stream("verona", realm)
realm.save(
update_fields=[
"zulip_update_announcements_level",
"zulip_update_announcements_stream",
]
)
group_direct_messages = Message.objects.filter(
realm=realm, recipient__type=Recipient.DIRECT_MESSAGE_GROUP
)
self.assertFalse(group_direct_messages.exists())
# post-upgrade hook sends a group DM.
now = timezone_now()
with time_machine.travel(now, tick=False):
send_zulip_update_announcements(skip_delay=False)
realm.refresh_from_db()
self.assertTrue(group_direct_messages.exists())
self.assertEqual(realm.zulip_update_announcements_level, 0)
# For self-hosted servers, 9.0 upgrade notes suggests to run
# 'send_zulip_update_announcements' management command with
# '--skip-delay' argument to immediately send update messages.
# 'zulip_update_announcements_stream' should be configured.
with time_machine.travel(now, tick=False):
send_zulip_update_announcements(skip_delay=True)
realm.refresh_from_db()
self.assertEqual(realm.zulip_update_announcements_level, 2)
def test_group_direct_message_with_zulip_updates_stream_set(self) -> None:
realm = get_realm("zulip")
@ -214,7 +256,7 @@ class ZulipUpdateAnnouncementsTest(ZulipTestCase):
now = timezone_now()
with time_machine.travel(now, tick=False):
send_zulip_update_announcements()
send_zulip_update_announcements(skip_delay=False)
realm.refresh_from_db()
group_direct_message = group_direct_messages.first()