mirror of https://github.com/zulip/zulip.git
management: Add option to reset all the active realms to a level.
This commit adds a --reset-level optional argument to send_zulip_update_announcements management command to reset all the active realms to a given level.
This commit is contained in:
parent
1dc7ad13a9
commit
9a40319bfc
|
@ -1,10 +1,12 @@
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
|
from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
|
||||||
from zerver.lib.zulip_update_announcements import send_zulip_update_announcements
|
from zerver.lib.zulip_update_announcements import send_zulip_update_announcements
|
||||||
|
from zerver.models import Realm
|
||||||
|
|
||||||
|
|
||||||
class Command(ZulipBaseCommand):
|
class Command(ZulipBaseCommand):
|
||||||
|
@ -17,8 +19,19 @@ class Command(ZulipBaseCommand):
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Immediately send updates if 'zulip_update_announcements_stream' is configured.",
|
help="Immediately send updates if 'zulip_update_announcements_stream' is configured.",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--reset-level",
|
||||||
|
type=int,
|
||||||
|
help="The level to reset all active realms to.",
|
||||||
|
)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@abort_unless_locked
|
@abort_unless_locked
|
||||||
def handle(self, *args: Any, **options: Any) -> None:
|
def handle(self, *args: Any, **options: Any) -> None:
|
||||||
|
if options["reset_level"] is not None:
|
||||||
|
Realm.objects.filter(deactivated=False).exclude(
|
||||||
|
string_id=settings.SYSTEM_BOT_REALM
|
||||||
|
).update(zulip_update_announcements_level=options["reset_level"])
|
||||||
|
return
|
||||||
|
|
||||||
send_zulip_update_announcements(skip_delay=options["skip_delay"])
|
send_zulip_update_announcements(skip_delay=options["skip_delay"])
|
||||||
|
|
|
@ -588,3 +588,17 @@ class TestSendCustomEmail(ZulipTestCase):
|
||||||
call(" hamlet@zulip.com (zulip)"),
|
call(" hamlet@zulip.com (zulip)"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestSendZulipUpdateAnnouncements(ZulipTestCase):
|
||||||
|
COMMAND_NAME = "send_zulip_update_announcements"
|
||||||
|
|
||||||
|
def test_reset_level(self) -> None:
|
||||||
|
realm = get_realm("zulip")
|
||||||
|
realm.zulip_update_announcements_level = 9
|
||||||
|
realm.save()
|
||||||
|
|
||||||
|
call_command(self.COMMAND_NAME, "--reset-level=5")
|
||||||
|
|
||||||
|
realm.refresh_from_db()
|
||||||
|
self.assertEqual(realm.zulip_update_announcements_level, 5)
|
||||||
|
|
Loading…
Reference in New Issue