2014-01-15 16:08:39 +01:00
|
|
|
from __future__ import absolute_import
|
2015-11-01 17:11:06 +01:00
|
|
|
from __future__ import print_function
|
2014-01-15 16:08:39 +01:00
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
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
|
|
|
|
from zerver.models import UserProfile
|
2014-01-15 16:08:39 +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
|
|
|
|
2016-11-03 10:22:19 +01:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
# type: (CommandParser) -> None
|
|
|
|
parser.add_argument('-u', '--users',
|
|
|
|
dest='users',
|
|
|
|
type=str,
|
|
|
|
help='Turn off digests for this comma-separated '
|
|
|
|
'list of email addresses.')
|
2017-07-08 14:06:01 +02:00
|
|
|
self.add_realm_args(parser)
|
2014-01-15 16:08:39 +01:00
|
|
|
|
|
|
|
def handle(self, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (**str) -> None
|
2017-07-08 14:06:01 +02:00
|
|
|
realm = self.get_realm(options)
|
|
|
|
if realm is None and options["users"] is None:
|
2016-11-22 01:44:16 +01:00
|
|
|
self.print_help("./manage.py", "turn_off_digests")
|
2014-01-15 16:08:39 +01:00
|
|
|
exit(1)
|
|
|
|
|
2017-07-08 14:06:01 +02:00
|
|
|
if realm and not options["users"]:
|
2014-01-15 16:08:39 +01:00
|
|
|
user_profiles = UserProfile.objects.filter(realm=realm)
|
|
|
|
else:
|
|
|
|
emails = set([email.strip() for email in options["users"].split(",")])
|
|
|
|
user_profiles = []
|
|
|
|
for email in emails:
|
2017-07-08 14:06:01 +02:00
|
|
|
user_profiles.append(self.get_user(email, 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:
|
2017-05-23 03:19:21 +02:00
|
|
|
do_change_notification_settings(user_profile, 'enable_digest_emails', False)
|
2014-01-15 16:08:39 +01:00
|
|
|
else:
|
|
|
|
already_disabled_prefix = "(already off) "
|
2015-11-01 17:11:06 +01:00
|
|
|
print("%s%s <%s>" % (already_disabled_prefix, user_profile.full_name,
|
|
|
|
user_profile.email))
|