From 5e24e8307f650e72881f747661a2b6e52db15f2d Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Tue, 17 Nov 2026 19:43:04 +0100 Subject: feat(receiver): add Webmention detail and status history Add an authenticated detail view with full failure information, timestamps, actions, public status links, and recorded lifecycle transitions. Persist verification and resubmission events, backfill existing rows during migration, and clean up history when received Webmentions are deleted. --- webmentions_ssg/views/received.py | 82 ++++++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 15 deletions(-) (limited to 'webmentions_ssg/views/received.py') diff --git a/webmentions_ssg/views/received.py b/webmentions_ssg/views/received.py index 7d633ab..84c5750 100644 --- a/webmentions_ssg/views/received.py +++ b/webmentions_ssg/views/received.py @@ -22,7 +22,12 @@ from ..forms.received import ( ReceivedWebmentionFilterForm, default_received_page_size, ) -from ..models.received import ReceivedWebmention, ReceivedWebmentionStatus +from ..models.received import ( + ReceivedWebmention, + ReceivedWebmentionStatus, + ReceivedWebmentionStatusEvent, + purge_orphaned_received_events, +) from ..moderation_policy import domain_from_url from ..tasks.verification import verify_webmention from .blueprint import webmentions_bp @@ -169,6 +174,46 @@ def received_list() -> ResponseReturnValue: ) +@webmentions_bp.get("/received/") +@login_required +def received_detail(webmention_uuid: uuid.UUID) -> ResponseReturnValue: + """Display a private received Webmention detail and its recorded history.""" + filters = received_filter_args(received_filter_form()) + webmention = db.get_or_404(ReceivedWebmention, webmention_uuid) + history = db.session.scalars( + sa.select(ReceivedWebmentionStatusEvent) + .where(ReceivedWebmentionStatusEvent.webmention_uuid == webmention_uuid) + .order_by(ReceivedWebmentionStatusEvent.id.desc()) + ).all() + page = request.args.get("page", 1, type=int) + return render_template( + "received_detail.html", + title="Received Webmention details", + webmention=webmention, + history=history, + filters=filters, + page=page, + action_form=ConfirmActionForm(), + ) + + +def received_action_redirect( + webmention_uuid: uuid.UUID, filters: ReceivedFilterArgs +) -> ResponseReturnValue: + """Return to details for detail actions, otherwise to the filtered list.""" + page = request.args.get("page", 1, type=int) + if request.args.get("return_to") == "detail": + return redirect( + url_for( + "webmentions.received_detail", + webmention_uuid=webmention_uuid, + page=page, + **filters, + ) + ) + return redirect(url_for("webmentions.received_list", page=page, **filters)) + + @webmentions_bp.post("/received//delete") @login_required def delete_received_webmention(webmention_uuid: uuid.UUID) -> ResponseReturnValue: @@ -214,6 +259,14 @@ def reverify_received_webmention(webmention_uuid: uuid.UUID) -> ResponseReturnVa webmention = db.get_or_404(ReceivedWebmention, webmention_uuid) webmention.reopen_verification() + db.session.add( + ReceivedWebmentionStatusEvent( + webmention_uuid=webmention_uuid, + status=ReceivedWebmentionStatus.RECEIVED, + action="Manually queued for reverification", + occurred_at=webmention.updated_at, + ) + ) db.session.commit() @@ -221,13 +274,7 @@ def reverify_received_webmention(webmention_uuid: uuid.UUID) -> ResponseReturnVa flash(f"Webmention {webmention.uuid} queued for reverification.", "success") - return redirect( - url_for( - "webmentions.received_list", - page=request.args.get("page", 1, type=int), - **filters, - ) - ) + return received_action_redirect(webmention_uuid, filters) def selected_received_webmentions() -> list[ReceivedWebmention]: @@ -274,6 +321,14 @@ def reverify_selected_received_webmentions() -> ResponseReturnValue: identifiers = [webmention.uuid for webmention in webmentions] for webmention in webmentions: webmention.reopen_verification() + db.session.add( + ReceivedWebmentionStatusEvent( + webmention_uuid=webmention.uuid, + status=ReceivedWebmentionStatus.RECEIVED, + action="Manually queued for reverification", + occurred_at=webmention.updated_at, + ) + ) db.session.commit() for identifier in identifiers: @@ -301,6 +356,8 @@ def delete_selected_received_webmentions() -> ResponseReturnValue: for webmention in webmentions: db.session.delete(webmention) + db.session.flush() + purge_orphaned_received_events() db.session.commit() flash(f"{len(webmentions)} Webmentions deleted.", "success") @@ -326,6 +383,7 @@ def delete_all_declined_received_webmentions() -> ResponseReturnValue: ReceivedWebmention.status.in_(RECEIVED_STATUS_FILTERS["declined"]) ) ) + purge_orphaned_received_events() db.session.commit() count = rows_affected(result) @@ -382,10 +440,4 @@ def block_received_source(webmention_uuid: uuid.UUID) -> ResponseReturnValue: block_domains({domain}) flash(f"Source domain {domain} blocked.", "success") - return redirect( - url_for( - "webmentions.received_list", - page=request.args.get("page", 1, type=int), - **filters, - ) - ) + return received_action_redirect(webmention_uuid, filters) -- cgit v1.3.1