2017-07-08 14:06:01 +02:00
|
|
|
from django.core.management.base import CommandParser
|
2014-01-15 16:08:39 +01:00
|
|
|
|
2017-05-23 03:19:21 +02:00
|
|
|
from zerver.lib.actions import do_change_notification_settings
|
2017-07-08 14:06:01 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2014-01-15 16:08:39 +01:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2017-07-08 14:06:01 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2016-11-16 21:16:02 +01:00
|
|
|
help = """Turn off digests for a subdomain/string_id or specified set of email addresses."""
|
2014-01-15 16:08:39 +01:00
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: CommandParser) -> None:
|
2017-07-08 14:06:01 +02:00
|
|
|
self.add_realm_args(parser)
|
2014-01-15 16:08:39 +01:00
|
|
|
|
2017-08-19 21:08:58 +02:00
|
|
|
self.add_user_list_args(parser,
|
2021-02-12 03:52:14 +01:00
|
|
|
help='Turn off digests for this comma-separated list of email addresses.',
|
2017-08-24 21:46:13 +02:00
|
|
|
all_users_help="Turn off digests for everyone in realm.")
|
2017-08-19 21:08:58 +02:00
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def handle(self, **options: str) -> None:
|
2017-07-08 14:06:01 +02:00
|
|
|
realm = self.get_realm(options)
|
2017-08-19 21:08:58 +02:00
|
|
|
user_profiles = self.get_users(options, realm)
|
2014-01-15 16:08:39 +01:00
|
|
|
|
2015-11-01 17:11:06 +01:00
|
|
|
print("Turned off digest emails for:")
|
2014-01-15 16:08:39 +01:00
|
|
|
for user_profile in user_profiles:
|
|
|
|
already_disabled_prefix = ""
|
|
|
|
if user_profile.enable_digest_emails:
|
2020-07-12 23:41:53 +02:00
|
|
|
do_change_notification_settings(user_profile, 'enable_digest_emails', False, acting_user=None)
|
2014-01-15 16:08:39 +01:00
|
|
|
else:
|
|
|
|
already_disabled_prefix = "(already off) "
|
2020-06-10 06:41:04 +02:00
|
|
|
print(f"{already_disabled_prefix}{user_profile.full_name} <{user_profile.delivery_email}>")
|