From d525c8fa41d1d973db432d018bc9ecfc36536ea7 Mon Sep 17 00:00:00 2001 From: Se Yeon Kim Date: Wed, 18 Aug 2021 14:07:53 -0500 Subject: [PATCH] Move domains to utils --- emails/models.py | 7 +++---- emails/utils.py | 9 +++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/emails/models.py b/emails/models.py index a7c9df539c..c58c1f5b82 100644 --- a/emails/models.py +++ b/emails/models.py @@ -10,6 +10,8 @@ from django.contrib.auth.models import User from django.db import models +from emails.utils import get_domains_from_settings + emails_config = apps.get_app_config('emails') @@ -18,10 +20,7 @@ NOT_PREMIUM_USER_ERR_MSG = 'You must be a premium subscriber to {}.' TRY_DIFFERENT_VALUE_ERR_MSG = '{} could not be created, try using a different value.' -DOMAINS = { - 'RELAY_FIREFOX_DOMAIN': settings.RELAY_FIREFOX_DOMAIN, - 'MOZMAIL_DOMAIN': settings.MOZMAIL_DOMAIN -} +DOMAINS = get_domains_from_settings() DOMAIN_CHOICES = [(1, 'RELAY_FIREFOX_DOMAIN'), (2, 'MOZMAIL_DOMAIN')] DEFAULT_DOMAIN = settings.RELAY_FIREFOX_DOMAIN diff --git a/emails/utils.py b/emails/utils.py index e265909efb..78622f1b83 100644 --- a/emails/utils.py +++ b/emails/utils.py @@ -45,8 +45,6 @@ def histogram_if_enabled(name, value, tags=None): def get_email_domain_from_settings(): - if settings.TEST_MOZMAIL and settings.ADDITIONAL_DOMAINS: - return settings.ADDITIONAL_DOMAINS[0] email_network_locality = urlparse(settings.SITE_ORIGIN).netloc # on Heroku we need to add "mail" prefix # because we can’t publish MX records on Heroku @@ -55,6 +53,13 @@ def get_email_domain_from_settings(): return email_network_locality +def get_domains_from_settings(): + return { + 'RELAY_FIREFOX_DOMAIN': settings.RELAY_FIREFOX_DOMAIN, + 'MOZMAIL_DOMAIN': settings.MOZMAIL_DOMAIN + } + + @time_if_enabled('ses_send_email') def ses_send_email(from_address, to_address, subject, message_body): emails_config = apps.get_app_config('emails')