From 806f7016aeac983579d4abf767e50c73eccb9274 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Thu, 7 May 2020 20:48:11 +0200 Subject: [PATCH] fix: wrongly set alias custom_domain when custom_domain is in EMAIL_ALIAS --- app/api/views/new_custom_alias.py | 14 ++++++-------- app/dashboard/views/custom_alias.py | 12 ++++++------ app/oauth/views/authorize.py | 8 ++++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/api/views/new_custom_alias.py b/app/api/views/new_custom_alias.py index 2dad4a32..4fe396ad 100644 --- a/app/api/views/new_custom_alias.py +++ b/app/api/views/new_custom_alias.py @@ -66,10 +66,9 @@ def new_custom_alias(): if alias_suffix.startswith("@"): alias_domain = alias_suffix[1:] - if alias_domain not in ALIAS_DOMAINS: - domain = CustomDomain.get_by(domain=alias_domain) - LOG.d("set alias %s to domain %s", full_alias, domain) - alias.custom_domain_id = domain.id + domain = CustomDomain.get_by(domain=alias_domain) + LOG.d("set alias %s to domain %s", full_alias, domain) + alias.custom_domain_id = domain.id db.session.commit() @@ -144,10 +143,9 @@ def new_custom_alias_v2(): if alias_suffix.startswith("@"): alias_domain = alias_suffix[1:] - if alias_domain not in ALIAS_DOMAINS: - domain = CustomDomain.get_by(domain=alias_domain) - LOG.d("set alias %s to domain %s", full_alias, domain) - alias.custom_domain_id = domain.id + domain = CustomDomain.get_by(domain=alias_domain) + LOG.d("set alias %s to domain %s", full_alias, domain) + alias.custom_domain_id = domain.id db.session.commit() diff --git a/app/dashboard/views/custom_alias.py b/app/dashboard/views/custom_alias.py index 0138efba..dff60699 100644 --- a/app/dashboard/views/custom_alias.py +++ b/app/dashboard/views/custom_alias.py @@ -8,7 +8,7 @@ from app.config import ( CUSTOM_ALIAS_SECRET, ) from app.dashboard.base import dashboard_bp -from app.email_utils import email_belongs_to_alias_domains, get_email_domain_part +from app.email_utils import email_belongs_to_alias_domains from app.extensions import db from app.log import LOG from app.models import Alias, CustomDomain, DeletedAlias, Mailbox, User @@ -101,11 +101,11 @@ def custom_alias(): ) # get the custom_domain_id if alias is created with a custom domain - alias_domain = get_email_domain_part(full_alias) - custom_domain = CustomDomain.get_by(domain=alias_domain) - if custom_domain: - LOG.d("Set alias %s domain to %s", full_alias, custom_domain) - alias.custom_domain_id = custom_domain.id + if alias_suffix.startswith("@"): + alias_domain = alias_suffix[1:] + domain = CustomDomain.get_by(domain=alias_domain) + LOG.d("Set alias %s domain to %s", full_alias, domain) + alias.custom_domain_id = domain.id db.session.commit() flash(f"Alias {full_alias} has been created", "success") diff --git a/app/oauth/views/authorize.py b/app/oauth/views/authorize.py index 9187f10b..71f538e4 100644 --- a/app/oauth/views/authorize.py +++ b/app/oauth/views/authorize.py @@ -187,10 +187,10 @@ def authorize(): ) # get the custom_domain_id if alias is created with a custom domain - alias_domain = get_email_domain_part(full_alias) - custom_domain = CustomDomain.get_by(domain=alias_domain) - if custom_domain: - alias.custom_domain_id = custom_domain.id + if alias_suffix.startswith("@"): + alias_domain = alias_suffix[1:] + domain = CustomDomain.get_by(domain=alias_domain) + alias.custom_domain_id = domain.id db.session.flush() flash(f"Alias {full_alias} has been created", "success")