Skip to content

Commit

Permalink
Fix #1421 as an operator I can maintain a list of suspected spam emai…
Browse files Browse the repository at this point in the history
…l domains and block them from connecting to a payment provider
  • Loading branch information
chrisjsimpson committed Nov 11, 2024
1 parent 65d6e69 commit 2323a81
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
34 changes: 34 additions & 0 deletions migrations/versions/abfb5c2f77e6_add_spamemaildomain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""add SpamEmailDomain
Revision ID: abfb5c2f77e6
Revises: abc1ff0c85e0
Create Date: 2024-11-11 21:27:48.094799
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "abfb5c2f77e6"
down_revision = "abc1ff0c85e0"
branch_labels = None
depends_on = None


def upgrade():
op.create_table(
"spam_email_domain",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("uuid", sa.String(), nullable=True),
sa.Column("ts", sa.DateTime(), nullable=True),
sa.Column("domain", sa.String(), nullable=True),
sa.Column("archived", sa.Boolean(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)


def downgrade():
pass
3 changes: 0 additions & 3 deletions settings.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ SUPPORTED_CURRENCIES: "GBP,USD,EUR"

# Anti spam
ANTI_SPAM_SHOP_NAMES_MODEL_FULL_PATH: "/path/to/classifier.pkl"
SUSPECTED_SPAM_EMAIL_DOMAINS:
- example.com
- mailfence.com

# Optional
TELEGRAM_TOKEN:
Expand Down
7 changes: 6 additions & 1 deletion subscribie/blueprints/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
UpcomingInvoice,
Document,
PlanQuestionAssociation,
SpamEmailDomain,
)
from .subscription import (
update_stripe_subscription_statuses,
Expand Down Expand Up @@ -995,9 +996,13 @@ def stripe_connect():
# Verify that shop owner email address is not
# a suspected SUSPECTED_SPAM_EMAIL_DOMAINS
user = User.query.first()
SUSPECTED_SPAM_EMAIL_DOMAINS = settings.get("SUSPECTED_SPAM_EMAIL_DOMAINS")
SUSPECTED_SPAM_EMAIL_DOMAINS = [d.domain for d in SpamEmailDomain.query.all()]
user_email_domain = user.email.split("@")[1]
if user_email_domain in SUSPECTED_SPAM_EMAIL_DOMAINS:
log.error(
f"SUSPECTED_SPAM_EMAIL_DOMAIN {user_email_domain} "
"attempted to connect stripe"
)
return "<h1>Please contact support before connecting Stripe, thank you.</h1>"
setting = Setting.query.first()
shop_activated = setting.shop_activated
Expand Down
11 changes: 10 additions & 1 deletion subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from sqlalchemy import Column
from sqlalchemy import Boolean
from sqlalchemy import PrimaryKeyConstraint
from sqlalchemy import desc

from typing import Optional
import datetime
Expand Down Expand Up @@ -1400,3 +1399,13 @@ class PriceListRule(database.Model, HasCreatedAt):
secondary=association_table_price_list_to_rule,
back_populates="rules",
)


class SpamEmailDomain(database.Model, HasArchived, HasCreatedAt):
__tablename__ = "spam_email_domain"
id = database.Column(database.Integer(), primary_key=True)
uuid = database.Column(database.String(), default=uuid_string)
ts = database.Column(
database.DateTime, default=lambda: datetime.datetime.now(datetime.UTC)
)
domain = database.Column(database.String())
3 changes: 1 addition & 2 deletions subscribie/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from strictyaml import load, Map, Email, Str, Url, Int, Bool, Regex, CommaSeparated, Seq
from strictyaml import load, Map, Email, Str, Url, Int, Bool, Regex, CommaSeparated
import os

# Load application settings according to schema
Expand Down Expand Up @@ -47,7 +47,6 @@
"PUBLIC_KEY": Str(),
"SUPPORTED_CURRENCIES": CommaSeparated(Str()),
"ANTI_SPAM_SHOP_NAMES_MODEL_FULL_PATH": Str(),
"SUSPECTED_SPAM_EMAIL_DOMAINS": Seq(Str()),
"TELEGRAM_TOKEN": Str(),
"TELEGRAM_CHAT_ID": Str(),
"TELEGRAM_PYTHON_LOG_LEVEL": Str(),
Expand Down

0 comments on commit 2323a81

Please sign in to comment.