Skip to content

Commit

Permalink
Add domain field in Relay Address model
Browse files Browse the repository at this point in the history
Set possible options for domain fields and set default domain
  • Loading branch information
say-yawn committed Jul 29, 2021
1 parent 9a98ad0 commit 94b06cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env-dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SECRET_KEY=unsafe-secret-key-for-dev-envs
ADMIN_ENABLED=
DEBUG=True
DJANGO_INTERNAL_IPS=127.0.0.1, localhost
ADDITIONAL_DOMAINS="mozmail.com,"
SENTRY_DSN=""
SERVE_ADDON="private_relay.zip"
AWS_REGION="us-east-1"
Expand Down
10 changes: 10 additions & 0 deletions emails/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.contrib.auth.models import User
from django.db import models

from emails.utils import get_email_domain_from_settings

emails_config = apps.get_app_config('emails')

Expand All @@ -19,6 +20,10 @@
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.'

DOMAIN_DEFAULT = get_email_domain_from_settings()
DOMAIN_CHOICES = [(item, item) for item in settings.ADDITIONAL_DOMAINS]
DOMAIN_CHOICES.append((DOMAIN_DEFAULT, DOMAIN_DEFAULT))


class Profile(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
Expand Down Expand Up @@ -193,6 +198,11 @@ class RelayAddress(models.Model):
address = models.CharField(
max_length=64, default=address_default, unique=True
)
domain = models.CharField(
choices=DOMAIN_CHOICES,
default=DOMAIN_DEFAULT,
max_length=64
)
enabled = models.BooleanField(default=True)
description = models.CharField(max_length=64, blank=True)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
Expand Down
1 change: 1 addition & 0 deletions privaterelay/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def _get_initial_middleware():
},
]

ADDITIONAL_DOMAINS = config('ADDITIONAL_DOMAINS', '', cast=str).split(',')
MAX_NUM_FREE_ALIASES = config('MAX_NUM_FREE_ALIASES', 5, cast=int)
PREMIUM_ENABLED = config('PREMIUM_ENABLED', default=False, cast=bool)
PREMIUM_PROD_ID = config('PREMIUM_PROD_ID', '', cast=str)
Expand Down

0 comments on commit 94b06cf

Please sign in to comment.