Merge pull request #84 from simple-login/auto-create-delete-alias
if alias has been deleted before, do not auto-create it with directory or catch-all domain
This commit is contained in:
commit
883fdb9f81
|
@ -68,6 +68,7 @@ from app.models import (
|
||||||
CustomDomain,
|
CustomDomain,
|
||||||
Directory,
|
Directory,
|
||||||
User,
|
User,
|
||||||
|
DeletedAlias,
|
||||||
)
|
)
|
||||||
from app.utils import random_string
|
from app.utils import random_string
|
||||||
from server import create_app
|
from server import create_app
|
||||||
|
@ -154,15 +155,29 @@ class MailHandler:
|
||||||
if directory:
|
if directory:
|
||||||
dir_user: User = directory.user
|
dir_user: User = directory.user
|
||||||
if dir_user.can_create_new_alias():
|
if dir_user.can_create_new_alias():
|
||||||
LOG.d("create alias %s for directory %s", alias, directory)
|
# if alias has been deleted before, do not auto-create it
|
||||||
on_the_fly = True
|
if DeletedAlias.get_by(
|
||||||
|
email=alias, user_id=directory.user_id
|
||||||
|
):
|
||||||
|
LOG.error(
|
||||||
|
"Alias %s has been deleted before, cannot auto-create using directory %s, user %s",
|
||||||
|
alias,
|
||||||
|
directory_name,
|
||||||
|
dir_user,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
|
||||||
gen_email = GenEmail.create(
|
LOG.d(
|
||||||
email=alias,
|
"create alias %s for directory %s", alias, directory
|
||||||
user_id=directory.user_id,
|
)
|
||||||
directory_id=directory.id,
|
on_the_fly = True
|
||||||
)
|
|
||||||
db.session.commit()
|
gen_email = GenEmail.create(
|
||||||
|
email=alias,
|
||||||
|
user_id=directory.user_id,
|
||||||
|
directory_id=directory.id,
|
||||||
|
)
|
||||||
|
db.session.commit()
|
||||||
else:
|
else:
|
||||||
LOG.error(
|
LOG.error(
|
||||||
"User %s is not premium anymore and cannot create alias with directory",
|
"User %s is not premium anymore and cannot create alias with directory",
|
||||||
|
@ -182,16 +197,27 @@ class MailHandler:
|
||||||
if custom_domain and custom_domain.catch_all:
|
if custom_domain and custom_domain.catch_all:
|
||||||
domain_user: User = custom_domain.user
|
domain_user: User = custom_domain.user
|
||||||
if domain_user.can_create_new_alias():
|
if domain_user.can_create_new_alias():
|
||||||
LOG.d("create alias %s for domain %s", alias, custom_domain)
|
# if alias has been deleted before, do not auto-create it
|
||||||
on_the_fly = True
|
if DeletedAlias.get_by(
|
||||||
|
email=alias, user_id=custom_domain.user_id
|
||||||
|
):
|
||||||
|
LOG.error(
|
||||||
|
"Alias %s has been deleted before, cannot auto-create using domain catch-all %s, user %s",
|
||||||
|
alias,
|
||||||
|
custom_domain,
|
||||||
|
domain_user,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
LOG.d("create alias %s for domain %s", alias, custom_domain)
|
||||||
|
on_the_fly = True
|
||||||
|
|
||||||
gen_email = GenEmail.create(
|
gen_email = GenEmail.create(
|
||||||
email=alias,
|
email=alias,
|
||||||
user_id=custom_domain.user_id,
|
user_id=custom_domain.user_id,
|
||||||
custom_domain_id=custom_domain.id,
|
custom_domain_id=custom_domain.id,
|
||||||
automatic_creation=True,
|
automatic_creation=True,
|
||||||
)
|
)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
else:
|
else:
|
||||||
LOG.error(
|
LOG.error(
|
||||||
"User %s is not premium anymore and cannot create alias with domain %s",
|
"User %s is not premium anymore and cannot create alias with domain %s",
|
||||||
|
|
Loading…
Reference in New Issue