use PublicDomain instead if ALIAS_DOMAINS
This commit is contained in:
parent
521d8e51a5
commit
adff510359
|
@ -5,7 +5,7 @@ from itsdangerous import Signer
|
|||
from wtforms import validators
|
||||
from wtforms.fields.html5 import EmailField
|
||||
|
||||
from app.config import EMAIL_DOMAIN, ALIAS_DOMAINS, MAILBOX_SECRET, URL
|
||||
from app.config import MAILBOX_SECRET, URL
|
||||
from app.dashboard.base import dashboard_bp
|
||||
from app.email_utils import (
|
||||
email_can_be_used_as_mailbox,
|
||||
|
@ -113,8 +113,6 @@ def mailbox_route():
|
|||
"dashboard/mailbox.html",
|
||||
mailboxes=mailboxes,
|
||||
new_mailbox_form=new_mailbox_form,
|
||||
EMAIL_DOMAIN=EMAIL_DOMAIN,
|
||||
ALIAS_DOMAINS=ALIAS_DOMAINS,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -383,10 +383,7 @@ def can_create_directory_for_address(address: str) -> bool:
|
|||
def is_valid_alias_address_domain(address) -> bool:
|
||||
"""Return whether an address domain might a domain handled by SimpleLogin"""
|
||||
domain = get_email_domain_part(address)
|
||||
if domain in ALIAS_DOMAINS:
|
||||
return True
|
||||
|
||||
if domain in PREMIUM_ALIAS_DOMAINS:
|
||||
if PublicDomain.get_by(domain=domain):
|
||||
return True
|
||||
|
||||
if CustomDomain.get_by(domain=domain, verified=True):
|
||||
|
@ -407,10 +404,7 @@ def email_can_be_used_as_mailbox(email: str) -> bool:
|
|||
if not domain:
|
||||
return False
|
||||
|
||||
if domain in ALIAS_DOMAINS:
|
||||
return False
|
||||
|
||||
if domain in PREMIUM_ALIAS_DOMAINS:
|
||||
if PublicDomain.get_by(domain=domain):
|
||||
return False
|
||||
|
||||
from app.models import CustomDomain
|
||||
|
|
|
@ -565,9 +565,12 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
- SimpleLogin public domains, available for all users (ALIAS_DOMAIN)
|
||||
- SimpleLogin premium domains, only available for Premium accounts (PREMIUM_ALIAS_DOMAIN)
|
||||
"""
|
||||
domains = ALIAS_DOMAINS
|
||||
if self.is_premium():
|
||||
domains += PREMIUM_ALIAS_DOMAINS
|
||||
query = PublicDomain.query.all()
|
||||
else:
|
||||
query = PublicDomain.filter_by(premium_only=False)
|
||||
|
||||
domains = [public_domain.domain for public_domain in query]
|
||||
|
||||
return domains
|
||||
|
||||
|
|
15
shell.py
15
shell.py
|
@ -100,18 +100,15 @@ def migrate_domain_trash():
|
|||
"""Move aliases from global trash to domain trash if applicable"""
|
||||
for deleted_alias in DeletedAlias.query.all():
|
||||
alias_domain = get_email_domain_part(deleted_alias.email)
|
||||
if (
|
||||
alias_domain not in ALIAS_DOMAINS
|
||||
and alias_domain not in PREMIUM_ALIAS_DOMAINS
|
||||
):
|
||||
domain = CustomDomain.get_by(domain=alias_domain)
|
||||
if domain:
|
||||
LOG.d("move %s to domain %s trash", deleted_alias, domain)
|
||||
if not PublicDomain.get_by(domain=alias_domain):
|
||||
custom_domain = CustomDomain.get_by(domain=alias_domain)
|
||||
if custom_domain:
|
||||
LOG.d("move %s to domain %s trash", deleted_alias, custom_domain)
|
||||
db.session.add(
|
||||
DomainDeletedAlias(
|
||||
user_id=domain.user_id,
|
||||
user_id=custom_domain.user_id,
|
||||
email=deleted_alias.email,
|
||||
domain_id=domain.id,
|
||||
domain_id=custom_domain.id,
|
||||
created_at=deleted_alias.created_at,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
|
||||
|
||||
os.environ["CONFIG"] = os.path.abspath(
|
||||
os.path.join(os.path.dirname(os.path.dirname(__file__)), "tests/test.env")
|
||||
)
|
||||
|
@ -13,6 +14,7 @@ import pytest
|
|||
|
||||
from app.extensions import db
|
||||
from server import create_app
|
||||
from init_app import add_public_domains
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -27,6 +29,7 @@ def flask_app():
|
|||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
add_public_domains()
|
||||
|
||||
yield app
|
||||
|
||||
|
@ -45,4 +48,5 @@ def flask_client():
|
|||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
add_public_domains()
|
||||
yield client
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
from app.models import User
|
||||
|
||||
|
||||
def test_available_sl_domains(flask_client):
|
||||
user = User.create(
|
||||
email="a@b.c",
|
||||
password="password",
|
||||
name="Test User",
|
||||
activated=True,
|
||||
commit=True,
|
||||
)
|
||||
|
||||
assert set(user.available_sl_domains()) == {"d1.test", "d2.test", "sl.local"}
|
Loading…
Reference in New Issue