mirror of
https://github.com/simple-login/app.git
synced 2025-09-04 05:35:18 +08:00
Add migration
This commit is contained in:
parent
3bef25b764
commit
6f391511b0
6 changed files with 51 additions and 5 deletions
|
@ -792,6 +792,12 @@ class InvalidMailboxDomainAdmin(SLModelView):
|
|||
can_delete = True
|
||||
|
||||
|
||||
class ForbiddenMxIpAdmin(SLModelView):
|
||||
form_base_class = SecureForm
|
||||
can_create = True
|
||||
can_delete = True
|
||||
|
||||
|
||||
class EmailSearchResult:
|
||||
def __init__(self):
|
||||
self.no_match: bool = True
|
||||
|
|
|
@ -57,7 +57,7 @@ from app.models import (
|
|||
InvalidMailboxDomain,
|
||||
VerpType,
|
||||
available_sl_email,
|
||||
ForbiddenMXIp,
|
||||
ForbiddenMxIp,
|
||||
)
|
||||
from app.utils import (
|
||||
random_string,
|
||||
|
@ -623,7 +623,7 @@ def email_can_be_used_as_mailbox(email_address: str) -> bool:
|
|||
if a_record is not None:
|
||||
mx_ips.add(a_record)
|
||||
if len(mx_ips) > 0:
|
||||
forbidden_ip = ForbiddenMXIp.filter(ForbiddenMXIp.ip.in_(list(mx_ips))).all()
|
||||
forbidden_ip = ForbiddenMxIp.filter(ForbiddenMxIp.ip.in_(list(mx_ips))).all()
|
||||
if forbidden_ip:
|
||||
LOG.i("Found forbidden MX ip %s", forbidden_ip)
|
||||
return False
|
||||
|
|
|
@ -3611,7 +3611,7 @@ class InvalidMailboxDomain(Base, ModelMixin):
|
|||
domain = sa.Column(sa.String(256), unique=True, nullable=False)
|
||||
|
||||
|
||||
class ForbiddenMXIp(Base, ModelMixin):
|
||||
class ForbiddenMxIp(Base, ModelMixin):
|
||||
"""MX IPs that we don't allow to create mailboxes for"""
|
||||
|
||||
__tablename__ = "forbidden_mx_ip"
|
||||
|
|
37
migrations/versions/2025_072815_9e80159405af_.py
Normal file
37
migrations/versions/2025_072815_9e80159405af_.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 9e80159405af
|
||||
Revises: e38002759d8f
|
||||
Create Date: 2025-07-28 15:14:34.829598
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '9e80159405af'
|
||||
down_revision = 'e38002759d8f'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('forbidden_mx_ip',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('created_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False),
|
||||
sa.Column('updated_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True),
|
||||
sa.Column('ip', sa.String(length=16), nullable=False),
|
||||
sa.Column('comment', sa.Text(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('ip')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('forbidden_mx_ip')
|
||||
# ### end Alembic commands ###
|
|
@ -45,6 +45,7 @@ from app.admin_model import (
|
|||
EmailSearchAdmin,
|
||||
CustomDomainSearchAdmin,
|
||||
AbuserLookupAdmin,
|
||||
ForbiddenMxIpAdmin,
|
||||
)
|
||||
from app.api.base import api_bp
|
||||
from app.auth.base import auth_bp
|
||||
|
@ -99,6 +100,7 @@ from app.models import (
|
|||
DailyMetric,
|
||||
Metric2,
|
||||
InvalidMailboxDomain,
|
||||
ForbiddenMxIp,
|
||||
)
|
||||
from app.monitor.base import monitor_bp
|
||||
from app.monitor_utils import send_version_event
|
||||
|
@ -475,6 +477,7 @@ def init_admin(app):
|
|||
admin.add_view(DailyMetricAdmin(DailyMetric, Session))
|
||||
admin.add_view(MetricAdmin(Metric2, Session))
|
||||
admin.add_view(InvalidMailboxDomainAdmin(InvalidMailboxDomain, Session))
|
||||
admin.add_view(ForbiddenMxIpAdmin(ForbiddenMxIp, Session))
|
||||
|
||||
|
||||
def register_custom_commands(app):
|
||||
|
|
|
@ -52,7 +52,7 @@ from app.models import (
|
|||
AliasGeneratorEnum,
|
||||
SLDomain,
|
||||
Mailbox,
|
||||
ForbiddenMXIp,
|
||||
ForbiddenMxIp,
|
||||
)
|
||||
|
||||
# flake8: noqa: E101, W191
|
||||
|
@ -150,7 +150,7 @@ def test_disabled_user_with_secondary_mailbox_prevents_email_from_being_used_as_
|
|||
def test_mx_invalid_ip():
|
||||
invalid_mx_ip = "12.2.23.23"
|
||||
valid_mx_ip = "1.1.1.1"
|
||||
ForbiddenMXIp.create(ip=invalid_mx_ip, flush=True)
|
||||
ForbiddenMxIp.create(ip=invalid_mx_ip, flush=True)
|
||||
dns_client.set_mx_records("testdomain.com", {10: ["mxdomain.com."]})
|
||||
dns_client.set_a_record("mxdomain.com", valid_mx_ip)
|
||||
assert email_can_be_used_as_mailbox("a@testdomain.com")
|
||||
|
|
Loading…
Add table
Reference in a new issue