take into account DISABLE_ALIAS_SUFFIX in /api/alias/options

This commit is contained in:
Son NK 2020-01-22 14:21:01 +01:00
parent 0c2b2ce60e
commit 926cc2935c
1 changed files with 9 additions and 4 deletions

View File

@ -3,7 +3,7 @@ from flask_cors import cross_origin
from sqlalchemy import desc
from app.api.base import api_bp, verify_api_key
from app.config import ALIAS_DOMAINS
from app.config import ALIAS_DOMAINS, DISABLE_ALIAS_SUFFIX
from app.extensions import db
from app.log import LOG
from app.models import AliasUsedOn, GenEmail, User
@ -71,7 +71,10 @@ def options():
# maybe better to make sure the suffix is never used before
# but this is ok as there's a check when creating a new custom alias
for domain in ALIAS_DOMAINS:
ret["custom"]["suffixes"].append(f".{random_word()}@{domain}")
if DISABLE_ALIAS_SUFFIX:
ret["custom"]["suffixes"].append(f"@{domain}")
else:
ret["custom"]["suffixes"].append(f".{random_word()}@{domain}")
for custom_domain in user.verified_custom_domains():
ret["custom"]["suffixes"].append("@" + custom_domain.domain)
@ -146,9 +149,11 @@ def options_v2():
# maybe better to make sure the suffix is never used before
# but this is ok as there's a check when creating a new custom alias
# todo: take into account DISABLE_ALIAS_SUFFIX
for domain in ALIAS_DOMAINS:
ret["suffixes"].append(f".{random_word()}@{domain}")
if DISABLE_ALIAS_SUFFIX:
ret["suffixes"].append(f"@{domain}")
else:
ret["suffixes"].append(f".{random_word()}@{domain}")
for custom_domain in user.verified_custom_domains():
ret["suffixes"].append("@" + custom_domain.domain)