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
|
|
|
|
|
2014-01-15 16:08:39 +01:00
|
|
|
from optparse import make_option
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
|
|
from zerver.lib.actions import do_change_enable_digest_emails
|
2015-10-13 22:54:35 +02:00
|
|
|
from zerver.models import Realm, UserProfile, get_realm, get_user_profile_by_email
|
2014-01-15 16:08:39 +01:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """Turn off digests for a domain or specified set of email addresses."""
|
|
|
|
|
|
|
|
option_list = BaseCommand.option_list + (
|
|
|
|
make_option('-d', '--domain',
|
|
|
|
dest='domain',
|
|
|
|
type='str',
|
|
|
|
help='Turn off digests for all users in this domain.'),
|
|
|
|
make_option('-u', '--users',
|
|
|
|
dest='users',
|
|
|
|
type='str',
|
|
|
|
help='Turn off digests for this comma-separated list of email addresses.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def handle(self, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (**str) -> None
|
2014-01-15 16:08:39 +01:00
|
|
|
if options["domain"] is None and options["users"] is None:
|
|
|
|
self.print_help("python manage.py", "turn_off_digests")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if options["domain"]:
|
2015-10-13 22:54:35 +02:00
|
|
|
realm = get_realm(options["domain"])
|
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:
|
|
|
|
user_profiles.append(get_user_profile_by_email(email))
|
|
|
|
|
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:
|
|
|
|
do_change_enable_digest_emails(user_profile, False)
|
|
|
|
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))
|