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:
Son Nguyen Kim 2020-02-15 21:20:55 +07:00 committed by GitHub
commit 883fdb9f81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 17 deletions

View File

@ -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,7 +155,21 @@ 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
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:
LOG.d(
"create alias %s for directory %s", alias, directory
)
on_the_fly = True on_the_fly = True
gen_email = GenEmail.create( gen_email = GenEmail.create(
@ -182,6 +197,17 @@ 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():
# if alias has been deleted before, do not auto-create it
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) LOG.d("create alias %s for domain %s", alias, custom_domain)
on_the_fly = True on_the_fly = True