diff --git a/app/dashboard/views/custom_domain.py b/app/dashboard/views/custom_domain.py index 620d2fa1..dfea5e84 100644 --- a/app/dashboard/views/custom_domain.py +++ b/app/dashboard/views/custom_domain.py @@ -7,6 +7,7 @@ from app.config import EMAIL_SERVERS_WITH_PRIORITY from app.dashboard.base import dashboard_bp from app.db import Session from app.email_utils import get_email_domain_part +from app.log import LOG from app.models import CustomDomain, Mailbox, DomainMailbox, SLDomain @@ -62,6 +63,19 @@ def custom_domain(): new_custom_domain = CustomDomain.create( domain=new_domain, user_id=current_user.id ) + # new domain has ownership verified if its parent has the ownership verified + for root_cd in current_user.custom_domains: + if ( + new_domain.endswith("." + root_cd.domain) + and root_cd.ownership_verified + ): + LOG.i( + "%s ownership verified thanks to %s", + new_custom_domain, + root_cd, + ) + new_custom_domain.ownership_verified = True + Session.commit() mailbox_ids = request.form.getlist("mailbox_ids") diff --git a/app/models.py b/app/models.py index f238f642..32025acc 100644 --- a/app/models.py +++ b/app/models.py @@ -1954,7 +1954,7 @@ class CustomDomain(Base, ModelMixin): ), # The condition ) - user = orm.relationship(User, foreign_keys=[user_id]) + user = orm.relationship(User, foreign_keys=[user_id], backref="custom_domains") @property def mailboxes(self):