move get_custom_domain() to alias_utils
This commit is contained in:
parent
55e3203512
commit
b7e8324e5a
|
@ -27,6 +27,7 @@ from app.models import (
|
|||
Mailbox,
|
||||
EmailLog,
|
||||
Contact,
|
||||
SLDomain,
|
||||
)
|
||||
from app.regex_utils import regex_match
|
||||
|
||||
|
@ -274,3 +275,15 @@ def check_alias_prefix(alias_prefix) -> bool:
|
|||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def get_custom_domain(alias_address) -> Optional[CustomDomain]:
|
||||
alias_domain = validate_email(
|
||||
alias_address, check_deliverability=False, allow_smtputf8=False
|
||||
).domain
|
||||
|
||||
# handle the case a SLDomain is also a CustomDomain
|
||||
if SLDomain.get_by(domain=alias_domain) is None:
|
||||
custom_domain = CustomDomain.get_by(domain=alias_domain)
|
||||
if custom_domain:
|
||||
return custom_domain
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
from typing import Optional
|
||||
|
||||
from email_validator import validate_email, EmailNotValidError
|
||||
from email_validator import EmailNotValidError
|
||||
from flask import g
|
||||
from flask import jsonify, request
|
||||
from itsdangerous import SignatureExpired
|
||||
|
||||
from app.alias_utils import check_alias_prefix
|
||||
from app.alias_utils import check_alias_prefix, get_custom_domain
|
||||
from app.api.base import api_bp, require_api_auth
|
||||
from app.api.serializer import (
|
||||
serialize_alias_info_v2,
|
||||
|
@ -20,28 +18,14 @@ from app.models import (
|
|||
Alias,
|
||||
AliasUsedOn,
|
||||
User,
|
||||
CustomDomain,
|
||||
DeletedAlias,
|
||||
DomainDeletedAlias,
|
||||
Mailbox,
|
||||
AliasMailbox,
|
||||
SLDomain,
|
||||
)
|
||||
from app.utils import convert_to_id
|
||||
|
||||
|
||||
def get_custom_domain(alias_address) -> Optional[CustomDomain]:
|
||||
alias_domain = validate_email(
|
||||
alias_address, check_deliverability=False, allow_smtputf8=False
|
||||
).domain
|
||||
|
||||
# handle the case a SLDomain is also a CustomDomain
|
||||
if SLDomain.get_by(domain=alias_domain) is None:
|
||||
custom_domain = CustomDomain.get_by(domain=alias_domain)
|
||||
if custom_domain:
|
||||
return custom_domain
|
||||
|
||||
|
||||
@api_bp.route("/v2/alias/custom/new", methods=["POST"])
|
||||
@limiter.limit(ALIAS_LIMIT)
|
||||
@require_api_auth
|
||||
|
|
Loading…
Reference in a new issue