handle the case alias is in trash
This commit is contained in:
parent
9c27f94e8e
commit
6eb702870c
|
@ -10,6 +10,7 @@ from app.api.serializer import (
|
||||||
from app.config import MAX_NB_EMAIL_FREE_PLAN, ALIAS_LIMIT
|
from app.config import MAX_NB_EMAIL_FREE_PLAN, ALIAS_LIMIT
|
||||||
from app.dashboard.views.custom_alias import get_available_suffixes
|
from app.dashboard.views.custom_alias import get_available_suffixes
|
||||||
from app.db import Session
|
from app.db import Session
|
||||||
|
from app.errors import AliasInTrashError
|
||||||
from app.extensions import limiter
|
from app.extensions import limiter
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import Alias, AliasUsedOn, AliasGeneratorEnum
|
from app.models import Alias, AliasUsedOn, AliasGeneratorEnum
|
||||||
|
@ -77,6 +78,7 @@ def new_random_alias():
|
||||||
alias = None
|
alias = None
|
||||||
elif not alias:
|
elif not alias:
|
||||||
LOG.d("create new alias %s", suggested_alias)
|
LOG.d("create new alias %s", suggested_alias)
|
||||||
|
try:
|
||||||
alias = Alias.create(
|
alias = Alias.create(
|
||||||
user_id=user.id,
|
user_id=user.id,
|
||||||
email=suggested_alias,
|
email=suggested_alias,
|
||||||
|
@ -84,6 +86,9 @@ def new_random_alias():
|
||||||
mailbox_id=user.default_mailbox_id,
|
mailbox_id=user.default_mailbox_id,
|
||||||
commit=True,
|
commit=True,
|
||||||
)
|
)
|
||||||
|
except AliasInTrashError:
|
||||||
|
LOG.i("Alias %s is in trash", suggested_alias)
|
||||||
|
alias = None
|
||||||
|
|
||||||
if not alias:
|
if not alias:
|
||||||
scheme = user.alias_generator
|
scheme = user.alias_generator
|
||||||
|
|
Loading…
Reference in a new issue