Add webhook management to feed detail page and corresponding tests

This commit is contained in:
Joakim Hellsén 2026-04-10 21:04:14 +02:00
commit 7435bba6f8
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
3 changed files with 109 additions and 0 deletions

View file

@ -1112,6 +1112,14 @@ async def get_feed( # noqa: C901, PLR0912, PLR0914, PLR0915
except FeedNotFoundError as e:
raise HTTPException(status_code=404, detail=f"Feed '{clean_feed_url}' not found.\n\n{e}") from e
webhooks: list[dict[str, str]] = cast("list[dict[str, str]]", list(reader.get_tag((), "webhooks", [])))
current_webhook_url: str = str(reader.get_tag(feed.url, "webhook", "")).strip()
current_webhook_name: str = ""
for hook in webhooks:
if hook.get("url", "").strip() == current_webhook_url:
current_webhook_name = hook.get("name", "").strip()
break
# Only show button if more than 10 entries.
total_entries: int = reader.get_entry_counts(feed=feed).total or 0
is_show_more_entries_button_visible: bool = total_entries > entries_per_page
@ -1157,6 +1165,9 @@ async def get_feed( # noqa: C901, PLR0912, PLR0914, PLR0915
"total_entries": total_entries,
"feed_interval": feed_interval,
"global_interval": global_interval,
"webhooks": webhooks,
"current_webhook_url": current_webhook_url,
"current_webhook_name": current_webhook_name,
}
return templates.TemplateResponse(request=request, name="feed.html", context=context)
@ -1213,6 +1224,9 @@ async def get_feed( # noqa: C901, PLR0912, PLR0914, PLR0915
"total_entries": total_entries,
"feed_interval": feed_interval,
"global_interval": global_interval,
"webhooks": webhooks,
"current_webhook_url": current_webhook_url,
"current_webhook_name": current_webhook_name,
}
return templates.TemplateResponse(request=request, name="feed.html", context=context)

View file

@ -171,6 +171,47 @@
</div>
</form>
</section>
<section class="mt-4 pt-3 border-top border-secondary-subtle">
<h3 class="h6 text-uppercase text-muted mb-3">Webhook</h3>
{% if current_webhook_name %}
<p class="text-muted mb-3">
Current webhook:
<strong>{{ current_webhook_name }}</strong>
</p>
{% elif current_webhook_url %}
<p class="text-warning mb-3">This feed references a missing webhook. Choose a webhook below to reattach it.</p>
{% else %}
<p class="text-warning mb-3">No webhook is attached to this feed yet.</p>
{% endif %}
{% if webhooks %}
<form action="/attach_feed_webhook"
method="post"
class="d-flex flex-wrap align-items-center gap-2 mb-0">
<input type="hidden" name="feed_url" value="{{ feed.url }}" />
<input type="hidden"
name="redirect_to"
value="/feed?feed_url={{ feed.url|encode_url }}" />
<select name="webhook_dropdown"
class="form-select form-select-sm bg-dark border-dark text-muted"
required>
<option value=""
disabled
{% if not current_webhook_name %}selected{% endif %}>
Select webhook...
</option>
{% for hook in webhooks %}
<option value="{{ hook.name }}"
{% if hook.name == current_webhook_name %}selected{% endif %}>
{{ hook.name }}
</option>
{% endfor %}
</select>
<button class="btn btn-outline-light btn-sm" type="submit">Save webhook</button>
</form>
{% else %}
<p class="text-muted mb-0">Add a webhook first to attach this feed.</p>
{% endif %}
</section>
<section class="mt-4 pt-3 border-top border-secondary-subtle">
<h3 class="h6 text-uppercase text-muted mb-3">Feed Information</h3>
<div class="row g-2 text-muted small">