aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/moderation_policy.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/moderation_policy.py (renamed from webmentions_ssg/source_policy.py)20
1 files changed, 10 insertions, 10 deletions
diff --git a/webmentions_ssg/source_policy.py b/webmentions_ssg/moderation_policy.py
index 2c62527..51e7995 100644
--- a/webmentions_ssg/source_policy.py
+++ b/webmentions_ssg/moderation_policy.py
@@ -11,11 +11,11 @@ from flask import current_app
from .extensions import db
from .hostname import normalize_hostname
-from .models import AllowedSource, BlockedSource
+from .models.moderation import AllowedDomain, BlockedDomain
-def source_domain_from_url(source: str) -> str | None:
- """Extract and canonicalize the source hostname without a network request."""
+def domain_from_url(source: str) -> str | None:
+ """Extract and canonicalize the hostname without a network request."""
try:
return normalize_hostname(source, from_url=True)
except ValueError:
@@ -23,7 +23,7 @@ def source_domain_from_url(source: str) -> str | None:
def has_matching_domain(
- model: type[AllowedSource | BlockedSource], domain: str
+ model: type[AllowedDomain | BlockedDomain], domain: str
) -> bool:
"""Match the hostname itself and parent domains, never partial labels."""
candidates = [domain]
@@ -42,20 +42,20 @@ def has_matching_domain(
)
-def source_rejection_reason(source: str) -> str | None:
- """Return the reason a source cannot be received, or None when accepted.
+def rejection_reason(source: str) -> str | None:
+ """Return the reason a source cannot be received, or ``None`` if accepted.
The blocklist always wins. In allowlist mode an empty allowlist rejects
every source. The database, not a stale per-worker cache, is consulted.
"""
- if (domain := source_domain_from_url(source)) is None:
+ if (domain := domain_from_url(source)) is None:
return "Invalid source hostname"
- if has_matching_domain(BlockedSource, domain):
+ if has_matching_domain(BlockedDomain, domain):
return "Source domain is blocked"
- if current_app.config["SOURCE_ALLOWLIST_ENABLED"] and not has_matching_domain(
- AllowedSource, domain
+ if current_app.config["ALLOWLIST_ENABLED"] and not has_matching_domain(
+ AllowedDomain, domain
):
return "Source domain is not allowlisted"