add can_be_used_as_personal_email()
This commit is contained in:
parent
ad2cd9f99d
commit
fc7a832969
|
@ -288,3 +288,23 @@ def email_belongs_to_alias_domains(email: str) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def can_be_used_as_personal_email(email: str) -> bool:
|
||||||
|
"""return True if an email can be used as a personal email. Currently the only condition is email domain is not
|
||||||
|
- one of ALIAS_DOMAINS
|
||||||
|
- one of custom domains
|
||||||
|
"""
|
||||||
|
domain = get_email_domain_part(email)
|
||||||
|
if not domain:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if domain in ALIAS_DOMAINS:
|
||||||
|
return False
|
||||||
|
|
||||||
|
from app.models import CustomDomain
|
||||||
|
|
||||||
|
if CustomDomain.get_by(domain=domain, verified=True):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
|
@ -4,7 +4,10 @@ from app.email_utils import (
|
||||||
get_email_local_part,
|
get_email_local_part,
|
||||||
get_email_domain_part,
|
get_email_domain_part,
|
||||||
email_belongs_to_alias_domains,
|
email_belongs_to_alias_domains,
|
||||||
|
can_be_used_as_personal_email,
|
||||||
)
|
)
|
||||||
|
from app.extensions import db
|
||||||
|
from app.models import User, CustomDomain
|
||||||
|
|
||||||
|
|
||||||
def test_get_email_name():
|
def test_get_email_name():
|
||||||
|
@ -36,3 +39,19 @@ def test_email_belongs_to_alias_domains():
|
||||||
|
|
||||||
assert email_belongs_to_alias_domains("hey@d1.test")
|
assert email_belongs_to_alias_domains("hey@d1.test")
|
||||||
assert not email_belongs_to_alias_domains("hey@d3.test")
|
assert not email_belongs_to_alias_domains("hey@d3.test")
|
||||||
|
|
||||||
|
|
||||||
|
def test_can_be_used_as_personal_email(flask_client):
|
||||||
|
# default alias domain
|
||||||
|
assert not can_be_used_as_personal_email("ab@sl.local")
|
||||||
|
assert not can_be_used_as_personal_email("hey@d1.test")
|
||||||
|
|
||||||
|
assert can_be_used_as_personal_email("hey@ab.cd")
|
||||||
|
# custom domain
|
||||||
|
user = User.create(
|
||||||
|
email="a@b.c", password="password", name="Test User", activated=True
|
||||||
|
)
|
||||||
|
db.session.commit()
|
||||||
|
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True)
|
||||||
|
db.session.commit()
|
||||||
|
assert not can_be_used_as_personal_email("hey@ab.cd")
|
||||||
|
|
Loading…
Reference in a new issue