diff options
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/migrations/versions/4e6fbc9d207a_source_document_events.py | 53 | ||||
| -rw-r--r-- | webmentions_ssg/models/sources.py | 49 | ||||
| -rw-r--r-- | webmentions_ssg/tasks/scanner.py | 5 | ||||
| -rw-r--r-- | webmentions_ssg/templates/moderation.html | 2 | ||||
| -rw-r--r-- | webmentions_ssg/templates/received.html | 8 | ||||
| -rw-r--r-- | webmentions_ssg/templates/sent.html | 37 | ||||
| -rw-r--r-- | webmentions_ssg/templates/sent_source.html | 227 | ||||
| -rw-r--r-- | webmentions_ssg/templates/sent_webmention_detail.html | 176 | ||||
| -rw-r--r-- | webmentions_ssg/views/__init__.py | 4 | ||||
| -rw-r--r-- | webmentions_ssg/views/sent.py | 97 |
10 files changed, 449 insertions, 209 deletions
diff --git a/webmentions_ssg/migrations/versions/4e6fbc9d207a_source_document_events.py b/webmentions_ssg/migrations/versions/4e6fbc9d207a_source_document_events.py new file mode 100644 index 0000000..eb162dd --- /dev/null +++ b/webmentions_ssg/migrations/versions/4e6fbc9d207a_source_document_events.py @@ -0,0 +1,53 @@ +# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me> +# +# SPDX-License-Identifier: BSD-3-Clause + +"""Record source-document lifecycle history separately from deliveries. + +Revision ID: 4e6fbc9d207a +Revises: c8fa49e1a203 +""" + +import sqlalchemy as sa +from alembic import op + +revision = "4e6fbc9d207a" +down_revision = "c8fa49e1a203" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.create_table( + "source_document_events", + sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True), + sa.Column("source_uuid", sa.Uuid(), nullable=False), + sa.Column("action", sa.String(length=80), nullable=False), + sa.Column("revision", sa.Integer(), nullable=False), + sa.Column("occurred_at", sa.DateTime(timezone=True), nullable=False), + sa.ForeignKeyConstraint( + ["source_uuid"], ["source_documents.uuid"], ondelete="CASCADE" + ), + ) + op.create_index( + "ix_source_document_events_source_id", + "source_document_events", + ["source_uuid", "id"], + ) + # The old schema did not retain lifecycle transitions. Seed one honest + # baseline snapshot per existing source; do not fabricate earlier events. + op.execute( + sa.text( + """INSERT INTO source_document_events + (source_uuid, action, revision, occurred_at) + SELECT uuid, 'Existing source at upgrade', revision, CURRENT_TIMESTAMP + FROM source_documents""" + ) + ) + + +def downgrade() -> None: + op.drop_index( + "ix_source_document_events_source_id", table_name="source_document_events" + ) + op.drop_table("source_document_events") diff --git a/webmentions_ssg/models/sources.py b/webmentions_ssg/models/sources.py index 9fc4212..9f2c2fc 100644 --- a/webmentions_ssg/models/sources.py +++ b/webmentions_ssg/models/sources.py @@ -23,7 +23,13 @@ from sqlalchemy import ( Uuid, ) from sqlalchemy.ext.hybrid import hybrid_property -from sqlalchemy.orm import Mapped, mapped_column, relationship, validates +from sqlalchemy.orm import ( + Mapped, + mapped_column, + object_session, + relationship, + validates, +) from ..extensions import Base from .utils import target_digest, uuid7_to_datetime @@ -65,6 +71,23 @@ class SourceDocument(Base): sent_webmentions: Mapped[list[SentWebmention]] = relationship( back_populates="source", cascade="all, delete-orphan" ) + history_events: Mapped[list[SourceDocumentEvent]] = relationship( + back_populates="source", cascade="all, delete-orphan" + ) + + def record_event(self, action: str, *, at: datetime | None = None) -> None: + """Record a source lifecycle change without including delivery events.""" + event = SourceDocumentEvent( + action=action, + revision=self.revision if self.revision is not None else 1, + occurred_at=at or datetime.now(UTC), + ) + if session := object_session(self): + # Do not load the entire history just to append one new event. + event.source = self + session.add(event) + else: + self.history_events.append(event) def __repr__(self) -> str: """Represent the source by its public URL.""" @@ -301,3 +324,27 @@ class SentWebmentionStatusEvent(Base): "ix_sent_webmention_status_events_webmention_id", "webmention_uuid", "id" ), ) + + +class SourceDocumentEvent(Base): + """Record discovery, revision, removal, and restoration of a source page.""" + + __tablename__ = "source_document_events" + + id: Mapped[int] = mapped_column(Integer(), primary_key=True, autoincrement=True) + source_uuid: Mapped[UUID] = mapped_column( + Uuid(as_uuid=True), + ForeignKey("source_documents.uuid", ondelete="CASCADE"), + nullable=False, + ) + action: Mapped[str] = mapped_column(String(80), nullable=False) + revision: Mapped[int] = mapped_column(Integer(), nullable=False) + occurred_at: Mapped[datetime] = mapped_column( + DateTime(timezone=True), nullable=False + ) + + source: Mapped[SourceDocument] = relationship(back_populates="history_events") + + __table_args__ = ( + Index("ix_source_document_events_source_id", "source_uuid", "id"), + ) diff --git a/webmentions_ssg/tasks/scanner.py b/webmentions_ssg/tasks/scanner.py index 9058b9b..6d4045e 100644 --- a/webmentions_ssg/tasks/scanner.py +++ b/webmentions_ssg/tasks/scanner.py @@ -49,6 +49,8 @@ def build_source(scanned: ScannedSource, scan_time: datetime) -> SourceDocument: deleted_at=None, ) + source.record_event("Discovered", at=scan_time) + for target in scanned.targets: source.sent_webmentions.append( SentWebmention(target=target, linked=True, desired_revision=1) @@ -83,10 +85,12 @@ def apply_scan_to_source( if source.deleted_at is None and source.content_hash == scanned.content_hash: return source + restored = source.deleted_at is not None source.revision += 1 source.content_hash = scanned.content_hash source.revised_at = scan_time source.deleted_at = None + source.record_event("Restored" if restored else "Revised", at=scan_time) existing = {webmention.target: webmention for webmention in source.sent_webmentions} @@ -219,6 +223,7 @@ def mark_missing_sources_deleted( source.revision += 1 source.revised_at = scan_time source.deleted_at = scan_time + source.record_event("Deleted", at=scan_time) marked += 1 for webmention in source.sent_webmentions: diff --git a/webmentions_ssg/templates/moderation.html b/webmentions_ssg/templates/moderation.html index 3c1e549..2fd922b 100644 --- a/webmentions_ssg/templates/moderation.html +++ b/webmentions_ssg/templates/moderation.html @@ -54,7 +54,7 @@ SPDX-License-Identifier: BSD-3-Clause method="post"> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"> <button type="submit" - class="btn btn-sm btn-outline-danger">{{ "Unblock" if kind == "blocked" else "Remove" }}</button> + class="btn btn-sm btn-danger">{{ "Unblock" if kind == "blocked" else "Remove" }}</button> </form> </td> </tr> diff --git a/webmentions_ssg/templates/received.html b/webmentions_ssg/templates/received.html index e7ec5a8..323475a 100644 --- a/webmentions_ssg/templates/received.html +++ b/webmentions_ssg/templates/received.html @@ -81,7 +81,7 @@ SPDX-License-Identifier: BSD-3-Clause <div class="col-auto d-flex gap-2 ms-auto"> <button type="submit" class="btn btn-primary">Filter</button> <a href="{{ url_for('webmentions.received_list') }}" - class="btn btn-outline-secondary">Clear</a> + class="btn btn-secondary">Clear</a> </div> </form> <div class="d-flex flex-wrap align-items-center gap-2 mb-3" @@ -92,7 +92,7 @@ SPDX-License-Identifier: BSD-3-Clause role="status" aria-live="polite">0 selected</span> <button type="button" - class="btn btn-sm btn-outline-primary d-none d-md-inline-block" + class="btn btn-sm btn-primary d-none d-md-inline-block" disabled data-bs-toggle="modal" data-bs-target="#confirmation-modal" @@ -103,7 +103,7 @@ SPDX-License-Identifier: BSD-3-Clause data-confirm-label="Reverify selected" data-confirm-class="btn-primary">Reverify selected</button> <button type="button" - class="btn btn-sm btn-outline-warning d-none d-md-inline-block" + class="btn btn-sm btn-warning d-none d-md-inline-block" disabled data-bs-toggle="modal" data-bs-target="#confirmation-modal" @@ -114,7 +114,7 @@ SPDX-License-Identifier: BSD-3-Clause data-confirm-label="Block selected domains" data-confirm-class="btn-warning">Block selected source domains</button> <button type="button" - class="btn btn-sm btn-outline-danger d-none d-md-inline-block" + class="btn btn-sm btn-danger d-none d-md-inline-block" disabled data-bs-toggle="modal" data-bs-target="#confirmation-modal" diff --git a/webmentions_ssg/templates/sent.html b/webmentions_ssg/templates/sent.html index 9dbbe8e..4a78fd1 100644 --- a/webmentions_ssg/templates/sent.html +++ b/webmentions_ssg/templates/sent.html @@ -25,15 +25,6 @@ SPDX-License-Identifier: BSD-3-Clause <h1 class="mb-0">Sent Webmentions</h1> <div class="d-flex flex-column justify-content-between"> <span class="text-body-secondary mb-1">{{ sources.total }} source document{{ "s" if sources.total != 1 else "" }}</span> - <button type="button" - class="btn btn-sm btn-primary" - data-bs-toggle="modal" - data-bs-target="#confirmation-modal" - data-action="{{ url_for('webmentions.rescan_sources', page=sources.page, **filters) }}" - data-title="Rescan sources?" - data-message="All sources will be scanned again for changes and webmentions." - data-confirm-label="Rescan" - data-confirm-class="btn-primary">Rescan</button> </div> </div> <form action="{{ url_for('webmentions.sent_list') }}" @@ -65,13 +56,22 @@ SPDX-License-Identifier: BSD-3-Clause <div class="col-auto d-flex gap-2 ms-auto"> <button type="submit" class="btn btn-primary">Filter</button> <a href="{{ url_for('webmentions.sent_list') }}" - class="btn btn-outline-secondary">Clear</a> + class="btn btn-secondary">Clear</a> </div> </form> - <div class="d-flex flex-wrap gap-2 mb-3" + <div class="d-flex justify-content-start flex-wrap gap-2 mb-3" aria-label="Sent Webmention actions"> <button type="button" - class="btn btn-sm btn-primary ms-auto" + class="btn btn-sm btn-primary" + data-bs-toggle="modal" + data-bs-target="#confirmation-modal" + data-action="{{ url_for('webmentions.rescan_sources', page=sources.page, **filters) }}" + data-title="Rescan sources?" + data-message="All sources will be scanned again for changes and webmentions." + data-confirm-label="Rescan" + data-confirm-class="btn-primary">Rescan</button> + <button type="button" + class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#confirmation-modal" data-action="{{ url_for('webmentions.resend_all_failed_webmentions', page=sources.page if sources.page > 1 else none, **filters) }}" @@ -87,10 +87,7 @@ SPDX-License-Identifier: BSD-3-Clause <tr> {{ sortable_header('Status', 'status') }} {{ sortable_header('Path', 'path') }} - {{ sortable_header('URL', 'url', 'd-none d-md-table-cell') }} {{ sortable_header('Webmentions', 'webmentions') }} - {{ sortable_header('Revision', 'revision', 'd-none d-md-table-cell') }} - {{ sortable_header('Created', 'created', 'd-none d-md-table-cell') }} {{ sortable_header('Last seen', 'last_seen', 'd-none d-md-table-cell') }} <th scope="col">Details</th> </tr> @@ -112,9 +109,6 @@ SPDX-License-Identifier: BSD-3-Clause <span class="badge {{ badge_class }}">{{ status_text }}</span> </td> <td class="text-break">{{ source.path }}</td> - <td class="text-break d-none d-md-table-cell"> - <a href="{{ source.url }}">{{ source.url }}</a> - </td> <td> <span class="badge text-bg-info">{{ counts.total }} Total</span> {% if counts.sent %} @@ -130,13 +124,6 @@ SPDX-License-Identifier: BSD-3-Clause <span class="badge text-bg-warning">{{ counts.retrying }} awaiting retry</span> {% endif %} </td> - <td class="d-none d-md-table-cell">{{ source.revision }}</td> - <td class="text-nowrap d-none d-md-table-cell"> - <time datetime="{{ source.created_at | utc_isoformat }}" - title="{{ source.created_at | utc_timestamp }}"> - {{ source.created_at | relative_time }} - </time> - </td> <td class="text-nowrap d-none d-md-table-cell"> <time datetime="{{ source.last_seen_at | utc_isoformat }}" title="{{ source.last_seen_at | utc_timestamp }}"> diff --git a/webmentions_ssg/templates/sent_source.html b/webmentions_ssg/templates/sent_source.html index 600934c..d3da4ea 100644 --- a/webmentions_ssg/templates/sent_source.html +++ b/webmentions_ssg/templates/sent_source.html @@ -6,20 +6,16 @@ SPDX-License-Identifier: BSD-3-Clause {% extends "base.html" %} {% from "bootstrap5/pagination.html" import render_pagination %} -{% from "includes/failure_guidance.html" import render_failure %} {% set sent_status_presentation = { "sent": { - "row_class": "table-success", "badge_class": "text-bg-success", "label": "Sent" }, "no_endpoint": { - "row_class": "table-warning", "badge_class": "text-bg-warning", "label": "Unsupported" }, "failed": { - "row_class": "table-danger", "badge_class": "text-bg-danger", "label": "Failed" } @@ -39,16 +35,8 @@ SPDX-License-Identifier: BSD-3-Clause </div> <section class="card mb-4" aria-labelledby="source-details-heading"> <div class="card-body"> - <h2 class="h4 card-title mb-3" id="source-details-heading">Details</h2> + <h2 class="h4 card-title mb-3" id="source-details-heading">Source details</h2> <dl class="row mb-0"> - <dt class="col-md-3">Source ID</dt> - <dd class="col-md-9"> - <code class="text-break">{{ source.uuid }}</code> - </dd> - <dt class="col-md-3">Content hash</dt> - <dd class="col-md-9"> - <code class="text-break">{{ source.content_hash }}</code> - </dd> <dt class="col-md-3">Path</dt> <dd class="col-md-9 text-break"> {{ source.path }} @@ -57,47 +45,54 @@ SPDX-License-Identifier: BSD-3-Clause <dd class="col-md-9 text-break"> <a href="{{ source.url }}">{{ source.url }}</a> </dd> + <dt class="col-md-3">Revision</dt> + <dd class="col-md-9"> + {{ source.revision }} + </dd> <dt class="col-md-3">Created</dt> <dd class="col-md-9"> <time datetime="{{ source.created_at | utc_isoformat }}" - title="{{ source.created_at | utc_timestamp }}"> - {{ source.created_at | relative_time }} - </time> + title="{{ source.created_at | utc_timestamp }}">{{ source.created_at | relative_time }}</time> </dd> <dt class="col-md-3">Last seen</dt> <dd class="col-md-9"> <time datetime="{{ source.last_seen_at | utc_isoformat }}" - title="{{ source.last_seen_at | utc_timestamp }}"> - {{ source.last_seen_at | relative_time }} - </time> + title="{{ source.last_seen_at | utc_timestamp }}">{{ source.last_seen_at | relative_time }}</time> </dd> - <dt class="col-md-3">Revised</dt> + <dt class="col-md-3">Last revised</dt> <dd class="col-md-9"> <time datetime="{{ source.revised_at | utc_isoformat }}" - title="{{ source.revised_at | utc_timestamp }}"> - {{ source.revised_at | relative_time }} - </time> + title="{{ source.revised_at | utc_timestamp }}">{{ source.revised_at | relative_time }}</time> </dd> - <dt class="col-md-3">Deleted</dt> - <dd class="col-md-9"> - {% if source.deleted_at is none %} - <span class="text-body-secondary">Never</span> - {% else %} + {% if source.deleted_at is not none %} + <dt class="col-md-3">Deleted</dt> + <dd class="col-md-9"> <time datetime="{{ source.deleted_at | utc_isoformat }}" - title="{{ source.deleted_at | utc_timestamp }}"> - {{ source.deleted_at | relative_time }} - </time> - {% endif %} + title="{{ source.deleted_at | utc_timestamp }}">{{ source.deleted_at | relative_time }}</time> + </dd> + {% endif %} + <dt class="col-md-3">Source ID</dt> + <dd class="col-md-9"> + <code class="text-break">{{ source.uuid }}</code> </dd> - <dt class="col-md-3">Revision</dt> + <dt class="col-md-3">Content hash</dt> <dd class="col-md-9"> - {{ source.revision }} + <code class="text-break">{{ source.content_hash }}</code> </dd> </dl> </div> </section> <div class="d-flex flex-wrap gap-2 mb-4" aria-label="Source actions"> <button type="button" + class="btn btn-sm btn-danger" + data-bs-toggle="modal" + data-bs-target="#confirmation-modal" + data-action="{{ url_for('webmentions.resend_failed_source_webmentions', source_uuid=source.uuid, source_page=source_page, page=webmentions.page, history_page=history.page, **filters) }}" + data-title="Resend all failed webmentions for this source?" + data-message="Only failed Webmentions belonging to this source will be queued again, including failed targets on other pages. Successful, unsupported, and pending Webmentions will not be resent." + data-confirm-label="Resend all failed" + data-confirm-class="btn-danger">Resend all failed</button> + <button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#confirmation-modal" @@ -110,7 +105,7 @@ SPDX-License-Identifier: BSD-3-Clause <section aria-labelledby="sent-webmentions-heading" class="mb-4"> <div class="d-flex justify-content-between align-items-center gap-2 mb-3"> <h2 class="h4 mb-0" id="sent-webmentions-heading">Sent Webmentions</h2> - <span class="text-body-secondary">{{ webmentions.total }} webmentions</span> + <span class="text-body-secondary">{{ webmentions.total }} targets</span> </div> {% if webmentions.items %} <div class="table-responsive"> @@ -119,121 +114,36 @@ SPDX-License-Identifier: BSD-3-Clause <tr> <th scope="col">Status</th> <th scope="col">Target</th> - <th scope="col" class="d-none d-md-table-cell">Active</th> - <th scope="col" class="d-none d-md-table-cell">Revisions</th> - <th scope="col" class="d-none d-md-table-cell">Delivery</th> - <th scope="col" class="d-none d-md-table-cell">Last activity</th> - <th scope="col">Actions</th> + <th scope="col" class="d-none d-md-table-cell">Link</th> + <th scope="col" class="d-none d-md-table-cell">Last attempt</th> + <th scope="col">Details</th> </tr> </thead> <tbody> {% for webmention in webmentions %} - {% set style = sent_status_presentation.get(webmention.status, {"row_class": "table-info", "badge_class": "text-bg-info", "label": "Pending" }) %} - <tr class="{{ style.row_class }}"> - <td class="text-break"> - <span class="badge {{ style.badge_class }}">{{ style.label }}</span> - {% if webmention.failure_reason is not none %} - <div class="small mt-2">{{ render_failure(webmention.failure_reason, "sent") }}</div> - {% endif %} - {% if webmention.awaiting_processing and webmention.attempt_count > 0 and webmention.next_retry_at is not none %} - <div class="small mt-2"> - Retry scheduled after attempt {{ webmention.attempt_count }}: - <time datetime="{{ webmention.next_retry_at | utc_isoformat }}" - title="{{ webmention.next_retry_at | utc_timestamp }}"> - {{ webmention.next_retry_at | relative_time }} - </time> - </div> - {% endif %} - </td> - <td class="text-break"> - <a href="{{ webmention.target }}">{{ webmention.target }}</a> - </td> + {% set style = sent_status_presentation.get(webmention.status, {"badge_class": "text-bg-info", "label": "Pending"}) %} + <tr> + <td><span class="badge {{ style.badge_class }}">{{ style.label }}</span></td> + <td class="text-break"><a href="{{ webmention.target }}">{{ webmention.target }}</a></td> <td class="d-none d-md-table-cell"> {% if webmention.linked %} - <span class="badge text-bg-success">Active</span> + <span class="badge text-bg-success">Linked</span> {% else %} - <span class="badge text-bg-danger">Removed</span> + <span class="badge text-bg-secondary">Removed</span> {% endif %} </td> - <td class="small text-nowrap d-none d-md-table-cell"> - <div> - <strong>Desired:</strong> - {{ webmention.desired_revision }} - </div> - <div> - <strong>Processed:</strong> - {{ webmention.processed_revision - if webmention.processed_revision is not none - else "—" }} - </div> - <div> - <strong>Sent:</strong> - {{ webmention.sent_revision - if webmention.sent_revision is not none - else "—" }} - </div> - </td> - <td class="small d-none d-md-table-cell"> - {% if webmention.webmention_endpoint is not none %} - <div class="mb-1"> - <strong>Endpoint:</strong> - <a href="{{ webmention.webmention_endpoint }}" - class="text-break">{{ webmention.webmention_endpoint }}</a> - </div> - {% endif %} - {% if webmention.endpoint_response_status is not none %} - <div class="mb-1"> - <strong>HTTP:</strong> - {{ webmention.endpoint_response_status }} - </div> - {% endif %} - {% if webmention.status_url is not none %} - <div> - <strong>Status:</strong> - {% if webmention.status_url | is_http_url %} - <a href="{{ webmention.status_url }}" class="text-break">{{ webmention.status_url }}</a> - {% else %} - <span class="text-break">{{ webmention.status_url }}</span> - {% endif %} - </div> + <td class="text-nowrap d-none d-md-table-cell"> + {% if webmention.last_attempted_at is not none %} + <time datetime="{{ webmention.last_attempted_at | utc_isoformat }}" + title="{{ webmention.last_attempted_at | utc_timestamp }}">{{ webmention.last_attempted_at | relative_time }}</time> + {% else %} + — {% endif %} </td> - <td class="small text-nowrap d-none d-md-table-cell"> - <div class="mb-1"> - <strong>Attempted:</strong> - <br> - {% if webmention.last_attempted_at is not none %} - <time datetime="{{ webmention.last_attempted_at | utc_isoformat }}" - title="{{ webmention.last_attempted_at | utc_timestamp }}"> - {{ webmention.last_attempted_at | relative_time }} - </time> - {% else %} - — - {% endif %} - </div> - <div> - <strong>Sent:</strong> - <br> - {% if webmention.last_sent_at is not none %} - <time datetime="{{ webmention.last_sent_at | utc_isoformat }}" - title="{{ webmention.last_sent_at | utc_timestamp }}"> - {{ webmention.last_sent_at | relative_time }} - </time> - {% else %} - — - {% endif %} - </div> - </td> <td> - <button type="button" - class="btn btn-sm btn-primary" - data-bs-toggle="modal" - data-bs-target="#confirmation-modal" - data-action="{{ url_for('webmentions.resend_webmention', source_uuid=source.uuid, webmention_uuid=webmention.uuid, source_page=source_page, page=webmentions.page, history_page=history.page, **filters) }}" - data-title="Resend Webmention?" - data-message="This Webmention will be queued again for delivery to {{ webmention.target }}." - data-confirm-label="Resend" - data-confirm-class="btn-primary">Resend</button> + <a class="btn btn-sm btn-primary" + href="{{ url_for('webmentions.sent_webmention_detail', source_uuid=source.uuid, webmention_uuid=webmention.uuid, source_page=source_page, page=webmentions.page, **filters) }}" + aria-label="Details for Webmention to {{ webmention.target }}">Details</a> </td> </tr> {% endfor %} @@ -247,35 +157,18 @@ SPDX-License-Identifier: BSD-3-Clause <p class="text-body-secondary">No Webmentions have been discovered for this source.</p> {% endif %} </section> - <section aria-labelledby="status-history-heading"> - <h2 class="h4 mb-3" id="status-history-heading">Status history</h2> + <section aria-labelledby="source-history-heading"> + <h2 class="h4 mb-3" id="source-history-heading">Source history</h2> {% if history.items %} - <ol class="list-group list-group-numbered mb-3"> + <ol class="list-group mb-3"> {% for event in history.items %} - {% set style = sent_status_presentation.get(event.status, {"badge_class": "text-bg-info", "label": "Pending"}) %} - <li class="list-group-item d-flex gap-2"> - <div class="flex-grow-1" style="min-width: 0;"> - <div class="d-flex flex-wrap align-items-center gap-2 mb-1"> - <span class="badge {{ style.badge_class }}">{{ style.label }}</span> - <strong>{{ event.action }}</strong> - <time class="ms-auto text-body-secondary small" - datetime="{{ event.occurred_at | utc_isoformat }}" - title="{{ event.occurred_at | utc_timestamp }}"> - {{ event.occurred_at | relative_time }} - </time> - </div> - <div class="text-break small mb-1"> - <a href="{{ event.webmention.target }}">{{ event.webmention.target }}</a> - </div> - <div class="small text-body-secondary"> - Revision {{ event.revision }} · Attempt {{ event.attempt_count }} - {% if event.endpoint_response_status is not none %} - · HTTP {{ event.endpoint_response_status }} - {% endif %} - </div> - {% if event.failure_reason %} - <div class="small mt-2">{{ render_failure(event.failure_reason, "sent") }}</div> - {% endif %} + <li class="list-group-item"> + <div class="d-flex flex-wrap align-items-center gap-2"> + <strong>{{ event.action }}</strong> + <span class="text-body-secondary small">Revision {{ event.revision }}</span> + <time class="ms-auto text-body-secondary small" + datetime="{{ event.occurred_at | utc_isoformat }}" + title="{{ event.occurred_at | utc_timestamp }}">{{ event.occurred_at | relative_time }}</time> </div> </li> {% endfor %} @@ -291,12 +184,12 @@ SPDX-License-Identifier: BSD-3-Clause source_page=source_page if source_page > 1 else none, webmentions_page=webmentions.page if webmentions.page > 1 else none ), - fragment='status-history-heading' + fragment='source-history-heading' ) }} </div> {% endif %} {% else %} - <p class="text-body-secondary">No historical delivery events were recorded for this source. Current Webmention statuses appear above.</p> + <p class="text-body-secondary">No source lifecycle events have been recorded yet. Delivery history is available on each Webmention's detail page.</p> {% endif %} </section> {% include "includes/confirmation_modal.html" %} diff --git a/webmentions_ssg/templates/sent_webmention_detail.html b/webmentions_ssg/templates/sent_webmention_detail.html new file mode 100644 index 0000000..fc7d7a4 --- /dev/null +++ b/webmentions_ssg/templates/sent_webmention_detail.html @@ -0,0 +1,176 @@ +<!-- +SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me> + +SPDX-License-Identifier: BSD-3-Clause +--> +{% extends "base.html" %} + +{% from "bootstrap5/pagination.html" import render_pagination %} +{% from "includes/failure_guidance.html" import render_failure %} +{% set sent_status_presentation = { + "sent": { + "badge_class": "text-bg-success", + "label": "Sent" + }, + "no_endpoint": { + "badge_class": "text-bg-warning", + "label": "Unsupported" + }, + "failed": { + "badge_class": "text-bg-danger", + "label": "Failed" + } +} %} + +{% block content %} + <div class="mb-3"> + <a href="{{ url_for('webmentions.sent_source_detail', source_uuid=source.uuid, source_page=source_page, page=webmentions_page, **filters) }}">← Back to source Webmentions</a> + </div> + <div class="d-flex flex-wrap justify-content-between align-items-center gap-2 mb-4"> + <h1 class="mb-0">Sent Webmention</h1> + {% set style = sent_status_presentation.get(webmention.status, {"badge_class": "text-bg-info", "label": "Pending"}) %} + <span class="badge fs-6 {{ style.badge_class }}">{{ style.label }}</span> + </div> + <section class="card mb-4" aria-labelledby="webmention-details-heading"> + <div class="card-body"> + <h2 class="h4 card-title mb-3" id="webmention-details-heading">Delivery details</h2> + <dl class="row mb-0"> + <dt class="col-md-3">Source</dt> + <dd class="col-md-9 text-break"> + <a href="{{ url_for('webmentions.sent_source_detail', source_uuid=source.uuid, source_page=source_page, page=webmentions_page, **filters) }}">{{ source.url }}</a> + </dd> + <dt class="col-md-3">Target</dt> + <dd class="col-md-9 text-break"> + <a href="{{ webmention.target }}">{{ webmention.target }}</a> + </dd> + <dt class="col-md-3">Link</dt> + <dd class="col-md-9"> + {{ 'Linked' if webmention.linked else 'Removed' }} + </dd> + <dt class="col-md-3">Created</dt> + <dd class="col-md-9"> + <time datetime="{{ webmention.created_at | utc_isoformat }}" + title="{{ webmention.created_at | utc_timestamp }}">{{ webmention.created_at | relative_time }}</time> + </dd> + <dt class="col-md-3">Revisions</dt> + <dd class="col-md-9"> + Desired {{ webmention.desired_revision }} · Processed {{ webmention.processed_revision if webmention.processed_revision is not none else '—' }} · Sent {{ webmention.sent_revision if webmention.sent_revision is not none else '—' }} + </dd> + <dt class="col-md-3">Attempts</dt> + <dd class="col-md-9"> + {{ webmention.attempt_count }} + </dd> + {% if webmention.next_retry_at is not none and webmention.awaiting_processing %} + <dt class="col-md-3">Next retry</dt> + <dd class="col-md-9"> + <time datetime="{{ webmention.next_retry_at | utc_isoformat }}" + title="{{ webmention.next_retry_at | utc_timestamp }}">{{ webmention.next_retry_at | relative_time }}</time> + </dd> + {% endif %} + <dt class="col-md-3">Last attempted</dt> + <dd class="col-md-9"> + {% if webmention.last_attempted_at is not none %} + <time datetime="{{ webmention.last_attempted_at | utc_isoformat }}" + title="{{ webmention.last_attempted_at | utc_timestamp }}">{{ webmention.last_attempted_at | relative_time }}</time> +{% else %}—{% endif %} + </dd> + <dt class="col-md-3">Last sent</dt> + <dd class="col-md-9"> + {% if webmention.last_sent_at is not none %} + <time datetime="{{ webmention.last_sent_at | utc_isoformat }}" + title="{{ webmention.last_sent_at | utc_timestamp }}">{{ webmention.last_sent_at | relative_time }}</time> +{% else %}—{% endif %} + </dd> + {% if webmention.webmention_endpoint is not none %} + <dt class="col-md-3">Endpoint</dt> + <dd class="col-md-9 text-break"> + <a href="{{ webmention.webmention_endpoint }}">{{ webmention.webmention_endpoint }}</a> + </dd> + {% endif %} + {% if webmention.endpoint_response_status is not none %} + <dt class="col-md-3">Endpoint HTTP</dt> + <dd class="col-md-9"> + {{ webmention.endpoint_response_status }} + </dd> + {% endif %} + {% if webmention.status_url is not none %} + <dt class="col-md-3">Status URL</dt> + <dd class="col-md-9 text-break"> + {% if webmention.status_url | is_http_url %}<a href="{{ webmention.status_url }}">{{ webmention.status_url }}</a>{% else %}{{ webmention.status_url }}{% endif %} + </dd> + {% endif %} + {% if webmention.failure_reason %} + <dt class="col-md-3">Failure</dt> + <dd class="col-md-9"> + {{ render_failure(webmention.failure_reason, "sent") }} + </dd> + {% endif %} + <dt class="col-md-3">Webmention ID</dt> + <dd class="col-md-9"> + <code class="text-break">{{ webmention.uuid }}</code> + </dd> + </dl> + </div> + </section> + <div class="d-flex flex-wrap gap-2 mb-4" aria-label="Webmention actions"> + <button type="button" + class="btn btn-sm btn-primary" + data-bs-toggle="modal" + data-bs-target="#confirmation-modal" + data-action="{{ url_for('webmentions.resend_webmention', source_uuid=source.uuid, webmention_uuid=webmention.uuid, return_to='detail', source_page=source_page, page=webmentions_page, history_page=history.page, **filters) }}" + data-title="Resend Webmention?" + data-message="This Webmention will be queued again for delivery to {{ webmention.target }}." + data-confirm-label="Resend" + data-confirm-class="btn-primary">Resend</button> + </div> + <section aria-labelledby="status-history-heading"> + <h2 class="h4 mb-3" id="status-history-heading">Delivery history</h2> + {% if history.items %} + <ol class="list-group mb-3"> + {% for event in history.items %} + {% set event_style = sent_status_presentation.get(event.status, {"badge_class": "text-bg-info", "label": "Pending"}) %} + <li class="list-group-item"> + <div class="d-flex flex-wrap align-items-center gap-2 mb-1"> + <span class="badge {{ event_style.badge_class }}">{{ event_style.label }}</span> + <strong>{{ event.action }}</strong> + <time class="ms-auto text-body-secondary small" + datetime="{{ event.occurred_at | utc_isoformat }}" + title="{{ event.occurred_at | utc_timestamp }}">{{ event.occurred_at | relative_time }}</time> + </div> + <div class="small text-body-secondary"> + Revision {{ event.revision }} · Attempt {{ event.attempt_count }} + {% if event.endpoint_response_status is not none %}· HTTP {{ event.endpoint_response_status }}{% endif %} + </div> + {% if event.failure_reason %} + <div class="small mt-2">{{ render_failure(event.failure_reason, "sent") }}</div> + {% endif %} + </li> + {% endfor %} + </ol> + {% if history.pages > 1 %} + <div class="mt-3"> + {{ render_pagination( + history, + endpoint='webmentions.sent_webmention_history_pagination', + args=dict( + filters, + source_uuid=source.uuid, + webmention_uuid=webmention.uuid, + source_page=source_page if source_page > 1 else none, + webmentions_page=webmentions_page if webmentions_page > 1 else none + ), + fragment='status-history-heading' + ) }} + </div> + {% endif %} + {% else %} + <p class="text-body-secondary">No delivery events have been recorded for this Webmention yet.</p> + {% endif %} + </section> + {% include "includes/confirmation_modal.html" %} +{% endblock %} + +{% block scripts %} + {{ super() }} + <script src="{{ url_for('static', filename='js/confirmation-modal.js') }}"></script> +{% endblock %} 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, + ) + ) |
