diff options
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/views/__init__.py | 4 | ||||
| -rw-r--r-- | webmentions_ssg/views/sent.py | 97 |
2 files changed, 90 insertions, 11 deletions
diff --git a/webmentions_ssg/views/__init__.py b/webmentions_ssg/views/__init__.py index 1701838..0f8efbc 100644 --- a/webmentions_ssg/views/__init__.py +++ b/webmentions_ssg/views/__init__.py @@ -4,7 +4,7 @@ """Collect and expose the routes for the blueprint.""" -from . import dashboard, endpoint, moderation, received, session, sent, user +from . import dashboard, endpoint, moderation, received, sent, session, user from .blueprint import webmentions_bp __all__ = [ @@ -12,8 +12,8 @@ __all__ = [ "endpoint", "moderation", "received", - "session", "sent", + "session", "user", "webmentions_bp", ] diff --git a/webmentions_ssg/views/sent.py b/webmentions_ssg/views/sent.py index 614d486..10ad34b 100644 --- a/webmentions_ssg/views/sent.py +++ b/webmentions_ssg/views/sent.py @@ -13,7 +13,6 @@ import sqlalchemy as sa from flask import abort, current_app, flash, redirect, render_template, request, url_for from flask.typing import ResponseReturnValue from flask_login import login_required -from sqlalchemy.orm import selectinload from ..extensions import db from ..failure_guidance import describe_sent_failure @@ -24,6 +23,7 @@ from ..models.sources import ( SentWebmentionStatus, SentWebmentionStatusEvent, SourceDocument, + SourceDocumentEvent, ) from ..tasks.scanner import manual_scan_sources from ..tasks.sender import send_webmention @@ -39,6 +39,11 @@ webmentions_bp.add_url_rule( endpoint="sent_source_history_pagination", build_only=True, ) +webmentions_bp.add_url_rule( + "/sent/<uuid:source_uuid>/<uuid:webmention_uuid>", + endpoint="sent_webmention_history_pagination", + build_only=True, +) @webmentions_bp.url_defaults @@ -46,7 +51,10 @@ def sent_history_pagination_url_defaults( endpoint: str, values: dict[str, object] ) -> None: """Map the macro's page number to the history pagination parameter.""" - if endpoint != "webmentions.sent_source_history_pagination": + if endpoint not in ( + "webmentions.sent_source_history_pagination", + "webmentions.sent_webmention_history_pagination", + ): return values["history_page"] = values.pop("page") @@ -246,11 +254,9 @@ def sent_source_detail(source_uuid: uuid.UUID) -> ResponseReturnValue: ) history = db.paginate( - sa.select(SentWebmentionStatusEvent) - .join(SentWebmention) - .options(selectinload(SentWebmentionStatusEvent.webmention)) - .where(SentWebmention.source_uuid == source.uuid) - .order_by(SentWebmentionStatusEvent.id.desc()), + sa.select(SourceDocumentEvent) + .where(SourceDocumentEvent.source_uuid == source.uuid) + .order_by(SourceDocumentEvent.id.desc()), page=request.args.get("history_page", 1, type=int), per_page=25, error_out=False, @@ -268,6 +274,39 @@ def sent_source_detail(source_uuid: uuid.UUID) -> ResponseReturnValue: ) +@webmentions_bp.route("/sent/<uuid:source_uuid>/<uuid:webmention_uuid>") +@login_required +def sent_webmention_detail( + source_uuid: uuid.UUID, webmention_uuid: uuid.UUID +) -> ResponseReturnValue: + """Show one target's delivery status and its own historical events.""" + filters = sent_filter_args(sent_filter_form()) + source = db.get_or_404(SourceDocument, source_uuid) + webmention = db.get_or_404(SentWebmention, webmention_uuid) + if webmention.source_uuid != source.uuid: + abort(HTTPStatus.NOT_FOUND) + + history = db.paginate( + sa.select(SentWebmentionStatusEvent) + .where(SentWebmentionStatusEvent.webmention_uuid == webmention.uuid) + .order_by(SentWebmentionStatusEvent.id.desc()), + page=request.args.get("history_page", 1, type=int), + per_page=25, + error_out=False, + ) + return render_template( + "sent_webmention_detail.html", + title="Sent Webmention", + source=source, + webmention=webmention, + history=history, + filters=filters, + source_page=request.args.get("source_page", 1, type=int), + webmentions_page=request.args.get("page", 1, type=int), + action_form=ConfirmActionForm(), + ) + + @webmentions_bp.post("/sent/<uuid:source_uuid>/<uuid:webmention_uuid>/resend") @login_required def resend_webmention( @@ -308,6 +347,18 @@ def resend_webmention( page = request.args.get("page", 1, type=int) source_page = request.args.get("source_page", 1, type=int) history_page = request.args.get("history_page", 1, type=int) + if request.args.get("return_to") == "detail": + return redirect( + url_for( + "webmentions.sent_webmention_detail", + source_uuid=source_uuid, + webmention_uuid=webmention_uuid, + page=page if page > 1 else None, + source_page=source_page if source_page > 1 else None, + history_page=history_page if history_page > 1 else None, + **filters, + ) + ) return redirect( url_for( "webmentions.sent_source_detail", @@ -325,8 +376,9 @@ def queue_sent_webmentions( ) -> list[uuid.UUID]: """Reopen sends in one transaction, then dispatch each task once. - A global retry selects only failed rows; a source-level retry can select - every delivery, regardless of status, list filters, or pagination. + By default, only failed rows are selected, optionally scoped to a source. + A source-level resend-all can explicitly include every status. Selection + does not depend on list filters or pagination. """ query = sa.select(SentWebmention) if failed_only: @@ -388,3 +440,30 @@ def resend_all_source_webmentions(source_uuid: uuid.UUID) -> ResponseReturnValue **filters, ) ) + + +@webmentions_bp.post("/sent/<uuid:source_uuid>/resend-failed") +@login_required +def resend_failed_source_webmentions(source_uuid: uuid.UUID) -> ResponseReturnValue: + """Resend only failed outgoing Webmentions for one source document.""" + if not ConfirmActionForm().validate_on_submit(): + abort(HTTPStatus.BAD_REQUEST) + + filters = sent_filter_args(sent_filter_form()) + db.get_or_404(SourceDocument, source_uuid) + identifiers = queue_sent_webmentions(source_uuid=source_uuid) + flash(f"{len(identifiers)} failed Webmentions queued for resend.", "success") + + page = request.args.get("page", 1, type=int) + history_page = request.args.get("history_page", 1, type=int) + source_page = request.args.get("source_page", 1, type=int) + return redirect( + url_for( + "webmentions.sent_source_detail", + source_uuid=source_uuid, + page=page if page > 1 else None, + history_page=history_page if history_page > 1 else None, + source_page=source_page if source_page > 1 else None, + **filters, + ) + ) |
