Skip to content

Commit

Permalink
Move domains to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
say-yawn committed Aug 18, 2021
1 parent 92dce9c commit d525c8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 3 additions & 4 deletions emails/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand All @@ -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

Expand Down
9 changes: 7 additions & 2 deletions emails/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit d525c8f

Please sign in to comment.