rename PublicDomain -> SLDomain
This commit is contained in:
parent
0a4fc76b61
commit
4a32db5b5d
|
@ -7,7 +7,7 @@ from app.config import EMAIL_SERVERS_WITH_PRIORITY
|
|||
from app.dashboard.base import dashboard_bp
|
||||
from app.email_utils import get_email_domain_part
|
||||
from app.extensions import db
|
||||
from app.models import CustomDomain, Mailbox, DomainMailbox, PublicDomain
|
||||
from app.models import CustomDomain, Mailbox, DomainMailbox, SLDomain
|
||||
|
||||
|
||||
class NewCustomDomainForm(FlaskForm):
|
||||
|
@ -40,7 +40,7 @@ def custom_domain():
|
|||
if new_domain.startswith("https://"):
|
||||
new_domain = new_domain[len("https://") :]
|
||||
|
||||
if PublicDomain.get_by(domain=new_domain):
|
||||
if SLDomain.get_by(domain=new_domain):
|
||||
flash("A custom domain cannot be a built-in domain.", "error")
|
||||
elif CustomDomain.get_by(domain=new_domain):
|
||||
flash(f"{new_domain} already added", "warning")
|
||||
|
|
|
@ -39,7 +39,7 @@ from app.models import (
|
|||
AliasGeneratorEnum,
|
||||
ManualSubscription,
|
||||
SenderFormatEnum,
|
||||
PublicDomain,
|
||||
SLDomain,
|
||||
)
|
||||
from app.utils import random_string
|
||||
|
||||
|
@ -200,7 +200,7 @@ def setting():
|
|||
default_domain = request.form.get("random-alias-default-domain")
|
||||
|
||||
if default_domain:
|
||||
public_domain: PublicDomain = PublicDomain.get_by(domain=default_domain)
|
||||
public_domain: SLDomain = SLDomain.get_by(domain=default_domain)
|
||||
if public_domain:
|
||||
if public_domain.premium_only and not current_user.is_premium():
|
||||
flash("You cannot use this domain", "error")
|
||||
|
|
|
@ -34,7 +34,7 @@ from app.config import (
|
|||
from app.dns_utils import get_mx_domains
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import Mailbox, User, SentAlert, CustomDomain, PublicDomain
|
||||
from app.models import Mailbox, User, SentAlert, CustomDomain, SLDomain
|
||||
|
||||
|
||||
def render(template_name, **kwargs) -> str:
|
||||
|
@ -380,7 +380,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 PublicDomain.get_by(domain=domain):
|
||||
if SLDomain.get_by(domain=domain):
|
||||
return True
|
||||
|
||||
if CustomDomain.get_by(domain=domain, verified=True):
|
||||
|
@ -401,7 +401,7 @@ def email_can_be_used_as_mailbox(email: str) -> bool:
|
|||
if not domain:
|
||||
return False
|
||||
|
||||
if PublicDomain.get_by(domain=domain):
|
||||
if SLDomain.get_by(domain=domain):
|
||||
return False
|
||||
|
||||
from app.models import CustomDomain
|
||||
|
@ -621,7 +621,7 @@ def to_bytes(msg: Message):
|
|||
|
||||
|
||||
def should_add_dkim_signature(domain: str) -> bool:
|
||||
if PublicDomain.get_by(domain=domain):
|
||||
if SLDomain.get_by(domain=domain):
|
||||
return True
|
||||
|
||||
custom_domain: CustomDomain = CustomDomain.get_by(domain=domain)
|
||||
|
|
|
@ -516,7 +516,7 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
return custom_domain.domain
|
||||
|
||||
if self.default_random_alias_public_domain_id:
|
||||
public_domain = PublicDomain.get(self.default_random_alias_public_domain_id)
|
||||
public_domain = SLDomain.get(self.default_random_alias_public_domain_id)
|
||||
# sanity check
|
||||
if not public_domain:
|
||||
LOG.exception("Problem with %s public random alias domain", self)
|
||||
|
@ -563,9 +563,9 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
- SimpleLogin premium domains, only available for Premium accounts (PREMIUM_ALIAS_DOMAIN)
|
||||
"""
|
||||
if self.is_premium():
|
||||
query = PublicDomain.query.all()
|
||||
query = SLDomain.query.all()
|
||||
else:
|
||||
query = PublicDomain.filter_by(premium_only=False)
|
||||
query = SLDomain.filter_by(premium_only=False)
|
||||
|
||||
domains = [public_domain.domain for public_domain in query]
|
||||
|
||||
|
@ -989,7 +989,7 @@ class Alias(db.Model, ModelMixin):
|
|||
scheme=scheme, in_hex=in_hex, alias_domain=custom_domain.domain
|
||||
)
|
||||
elif user.default_random_alias_public_domain_id:
|
||||
public_domain: PublicDomain = PublicDomain.get(
|
||||
public_domain: SLDomain = SLDomain.get(
|
||||
user.default_random_alias_public_domain_id
|
||||
)
|
||||
if public_domain.premium_only and not user.is_premium():
|
||||
|
@ -1834,9 +1834,11 @@ class Notification(db.Model, ModelMixin):
|
|||
read = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
||||
|
||||
class PublicDomain(db.Model, ModelMixin):
|
||||
class SLDomain(db.Model, ModelMixin):
|
||||
"""SimpleLogin domains"""
|
||||
|
||||
__tablename__ = "public_domain"
|
||||
|
||||
domain = db.Column(db.String(128), unique=True, nullable=False)
|
||||
|
||||
# only available for premium accounts
|
||||
|
@ -1845,9 +1847,7 @@ class PublicDomain(db.Model, ModelMixin):
|
|||
)
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
f"<PublicDomain {self.domain} {'Premium' if self.premium_only else 'Free'}"
|
||||
)
|
||||
return f"<SLDomain {self.domain} {'Premium' if self.premium_only else 'Free'}"
|
||||
|
||||
|
||||
class Monitoring(db.Model, ModelMixin):
|
||||
|
|
14
init_app.py
14
init_app.py
|
@ -1,6 +1,6 @@
|
|||
"""Initial loading script"""
|
||||
from app.config import ALIAS_DOMAINS, PREMIUM_ALIAS_DOMAINS
|
||||
from app.models import Mailbox, Contact, PublicDomain
|
||||
from app.models import Mailbox, Contact, SLDomain
|
||||
from app.log import LOG
|
||||
from app.extensions import db
|
||||
from app.pgp_utils import load_public_key
|
||||
|
@ -37,20 +37,20 @@ def load_pgp_public_keys():
|
|||
LOG.d("Finish load_pgp_public_keys")
|
||||
|
||||
|
||||
def add_public_domains():
|
||||
def add_sl_domains():
|
||||
for alias_domain in ALIAS_DOMAINS:
|
||||
if PublicDomain.get_by(domain=alias_domain):
|
||||
if SLDomain.get_by(domain=alias_domain):
|
||||
LOG.d("%s is already a public domain", alias_domain)
|
||||
else:
|
||||
LOG.info("Add %s to public domain", alias_domain)
|
||||
PublicDomain.create(domain=alias_domain)
|
||||
SLDomain.create(domain=alias_domain)
|
||||
|
||||
for premium_domain in PREMIUM_ALIAS_DOMAINS:
|
||||
if PublicDomain.get_by(domain=premium_domain):
|
||||
if SLDomain.get_by(domain=premium_domain):
|
||||
LOG.d("%s is already a public domain", premium_domain)
|
||||
else:
|
||||
LOG.info("Add %s to public domain", premium_domain)
|
||||
PublicDomain.create(domain=premium_domain, premium_only=True)
|
||||
SLDomain.create(domain=premium_domain, premium_only=True)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
@ -60,4 +60,4 @@ if __name__ == "__main__":
|
|||
|
||||
with app.app_context():
|
||||
load_pgp_public_keys()
|
||||
add_public_domains()
|
||||
add_sl_domains()
|
||||
|
|
|
@ -73,7 +73,7 @@ from app.models import (
|
|||
Referral,
|
||||
AliasMailbox,
|
||||
Notification,
|
||||
PublicDomain,
|
||||
SLDomain,
|
||||
)
|
||||
from app.monitor.base import monitor_bp
|
||||
from app.oauth.base import oauth_bp
|
||||
|
@ -303,7 +303,7 @@ def fake_data():
|
|||
db.session.commit()
|
||||
|
||||
for d in ["d1.localhost", "d2.localhost"]:
|
||||
PublicDomain.create(domain=d)
|
||||
SLDomain.create(domain=d)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
|
|
2
shell.py
2
shell.py
|
@ -100,7 +100,7 @@ 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 not PublicDomain.get_by(domain=alias_domain):
|
||||
if not SLDomain.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)
|
||||
|
|
|
@ -14,7 +14,7 @@ import pytest
|
|||
|
||||
from app.extensions import db
|
||||
from server import create_app
|
||||
from init_app import add_public_domains
|
||||
from init_app import add_sl_domains
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -29,7 +29,7 @@ def flask_app():
|
|||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
add_public_domains()
|
||||
add_sl_domains()
|
||||
|
||||
yield app
|
||||
|
||||
|
@ -48,5 +48,5 @@ def flask_client():
|
|||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
add_public_domains()
|
||||
add_sl_domains()
|
||||
yield client
|
||||
|
|
Loading…
Reference in New Issue