mirror of https://github.com/zulip/zulip.git
Change settings.SYSTEM_ONLY_REALMS to use Realm.string_id.
This commit is contained in:
parent
89af775e03
commit
38c2dc8790
|
@ -9,7 +9,7 @@ from django.conf import settings
|
|||
from django.core.management.base import BaseCommand
|
||||
|
||||
from zerver.lib.queue import queue_json_publish
|
||||
from zerver.models import UserActivity, UserProfile, get_realm, Realm
|
||||
from zerver.models import UserActivity, UserProfile, Realm
|
||||
|
||||
## Logging setup ##
|
||||
|
||||
|
@ -57,7 +57,7 @@ def queue_digest_recipient(user_profile, cutoff):
|
|||
"cutoff": cutoff.strftime('%s')}
|
||||
queue_json_publish("digest_emails", event, lambda event: None)
|
||||
|
||||
def domains_for_this_deployment():
|
||||
def realms_for_this_deployment():
|
||||
# type: () -> List[str]
|
||||
if settings.ZILENCER_ENABLED:
|
||||
# Voyager deployments don't have a Deployment entry.
|
||||
|
@ -70,18 +70,18 @@ def domains_for_this_deployment():
|
|||
except Deployment.DoesNotExist:
|
||||
raise ValueError("digest: Unable to determine deployment.")
|
||||
|
||||
return [r.domain for r in deployment.realms.all()]
|
||||
return [r.string_id for r in deployment.realms.all()]
|
||||
# Voyager and development.
|
||||
return []
|
||||
|
||||
def should_process_digest(domain, deployment_domains):
|
||||
def should_process_digest(realm_str, deployment_realms):
|
||||
# type: (str, List[str]) -> bool
|
||||
if domain in settings.SYSTEM_ONLY_REALMS:
|
||||
if realm_str in settings.SYSTEM_ONLY_REALMS:
|
||||
# Don't try to send emails to system-only realms
|
||||
return False
|
||||
if settings.PRODUCTION and not settings.VOYAGER:
|
||||
# zulip.com or staging.zulip.com
|
||||
return domain in deployment_domains
|
||||
return realm_str in deployment_realms
|
||||
return True
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -97,16 +97,13 @@ in a while.
|
|||
if datetime.datetime.utcnow().weekday() not in VALID_DIGEST_DAYS:
|
||||
return
|
||||
|
||||
deployment_domains = domains_for_this_deployment()
|
||||
deployment_realms = realms_for_this_deployment()
|
||||
for realm in Realm.objects.filter(deactivated=False, show_digest_email=True):
|
||||
domain = realm.domain
|
||||
if not should_process_digest(domain, deployment_domains):
|
||||
if not should_process_digest(realm.string_id, deployment_realms):
|
||||
continue
|
||||
|
||||
string_id = realm.string_id
|
||||
user_profiles = UserProfile.objects.filter(
|
||||
realm=get_realm(string_id), is_active=True, is_bot=False,
|
||||
enable_digest_emails=True)
|
||||
realm=realm, is_active=True, is_bot=False, enable_digest_emails=True)
|
||||
|
||||
for user_profile in user_profiles:
|
||||
cutoff = last_business_day()
|
||||
|
|
|
@ -270,7 +270,7 @@ def get_unique_open_realm():
|
|||
# On production installations, the (usually "zulip.com") system
|
||||
# realm is an empty realm just used for system bots, so don't
|
||||
# include it in this accounting.
|
||||
realms = realms.exclude(domain__in=settings.SYSTEM_ONLY_REALMS)
|
||||
realms = realms.exclude(string_id__in=settings.SYSTEM_ONLY_REALMS)
|
||||
if len(realms) != 1:
|
||||
return None
|
||||
realm = realms[0]
|
||||
|
|
|
@ -2283,7 +2283,7 @@ class TestOpenRealms(ZulipTestCase):
|
|||
mit_realm.save()
|
||||
self.assertTrue(completely_open(mit_realm))
|
||||
self.assertEqual(get_unique_open_realm(), None)
|
||||
with self.settings(SYSTEM_ONLY_REALMS={"zulip.com"}):
|
||||
with self.settings(SYSTEM_ONLY_REALMS={"zulip"}):
|
||||
self.assertEqual(get_unique_open_realm(), mit_realm)
|
||||
mit_realm.restricted_to_domain = True
|
||||
mit_realm.save()
|
||||
|
|
|
@ -185,7 +185,7 @@ DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '',
|
|||
'REALM_CREATION_LINK_VALIDITY_DAYS': 7,
|
||||
'TERMS_OF_SERVICE': None,
|
||||
'TOS_VERSION': None,
|
||||
'SYSTEM_ONLY_REALMS': {"zulip.com"},
|
||||
'SYSTEM_ONLY_REALMS': {"zulip"},
|
||||
'FIRST_TIME_TOS_TEMPLATE': None,
|
||||
'USING_PGROONGA': False,
|
||||
'POST_MIGRATION_CACHE_FLUSHING': False,
|
||||
|
|
Loading…
Reference in New Issue