aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/forms/endpoint.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-17 17:09:59 +0100
committerDennis Fink2026-11-17 17:09:59 +0100
commit6d6d079a3a99d3d3a922a640b6925eb2adf044de (patch)
tree33cc19241f4ce86ea43b2f194087c58e3fdc8a4d /webmentions_ssg/forms/endpoint.py
parent227092b57acc886469e16bcc4c0d3256e86d3d1e (diff)
downloadwebmentions-ssg-6d6d079a3a99d3d3a922a640b6925eb2adf044de.tar.gz
webmentions-ssg-6d6d079a3a99d3d3a922a640b6925eb2adf044de.zip
refactor(core)!: split forms and models by feature
Replace monolithic form and model modules with focused packages for receiver, moderation, source, user, and shared validation concerns. Rename source policy concepts to domain moderation, including routes, models, tables, configuration, templates, and tests. BREAKING CHANGE: form and model import paths, moderation routes, and `SOURCE_ALLOWLIST_ENABLED` have changed; use `ALLOWLIST_ENABLED` and the new feature-specific modules.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/forms/endpoint.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/webmentions_ssg/forms/endpoint.py b/webmentions_ssg/forms/endpoint.py
new file mode 100644
index 0000000..e063e73
--- /dev/null
+++ b/webmentions_ssg/forms/endpoint.py
@@ -0,0 +1,52 @@
+# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+"""Webmention submission form."""
+
+from flask_wtf import FlaskForm
+from wtforms import Field, StringField, ValidationError
+from wtforms.validators import InputRequired
+
+from .validators import (
+ AllowedTargetHostname,
+ MaxURLBytes,
+ RejectNonPublicIPLiteral,
+ StrictHTTPURL,
+)
+
+
+class WebmentionSubmissionForm(FlaskForm):
+ """Form for receiving a Webmention.
+
+ The source must be a public HTTP or HTTPS URL distinct from the target.
+ The target must be an HTTP or HTTPS URL using an allowed hostname.
+ """
+
+ source = StringField(
+ "source",
+ validators=[
+ InputRequired(),
+ MaxURLBytes(),
+ StrictHTTPURL(),
+ RejectNonPublicIPLiteral(),
+ ],
+ )
+ target = StringField(
+ "target",
+ validators=[
+ InputRequired(),
+ MaxURLBytes(),
+ StrictHTTPURL(),
+ AllowedTargetHostname(),
+ ],
+ )
+
+ def validate_source(self, field: Field) -> None:
+ """Reject a source URL that equals the target URL.
+
+ :param field: Source URL field being validated.
+ :raises ValidationError: If the source URL equals the target URL.
+ """
+ if field.data == self.target.data:
+ raise ValidationError(field.gettext("Field must not be equal to target."))