feat(activity): clearer cards, a Rejected view and Reopen for failed deliveries (#1618)

A batch of activity list changes from running it as an admin on my own
instance. They are separate commits that build on each other, so they
can be reviewed in order.

The cards read better. Every card gets a format pill (violet for audio,
orange for ebooks), the requester is named once, and finished cards say
how long a download took and how long ago it ended ("took 5m · 35m
ago"). A download that picked up work already under way shows a
Reattached pill.

Admins can tell what is automatic and what needs a person. A declined
request shows who declined it and when, anything with an `[auto]` note
reads "Declined automatically", and "Needs Review" becomes "No Match
Yet" with a line saying the search repeats on every sync.

There is a Rejected view next to History for admins, with Reopen on each
card and a way to hide the dead ones.

The part to read most carefully is the backend in `requests_service.py`
and `user_db.py`. An admin can now reopen a fulfilled request whose
download failed or was cancelled, and the reopen a failed download
triggers remembers which release failed, so the next search doesn't pick
it again.

I ran it on a scratch instance (when pulling them together to move from
my fork to upstream) as an admin with seeded requests and looked at the
pills, the durations, the wording and the Rejected view in a browser.
Reopening a fulfilled request I only exercised in the tests. The
frontend and Python suites, type check, ruff and basedpyright pass.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Admins can review rejected requests in a dedicated view, hide or
restore cards, and reopen requests.
* Fulfilled requests with failed or cancelled deliveries can be
reopened; the failed release is skipped in the next automatic search.
* Activity cards now show format badges, download timing, and when a
download resumes existing work.
* **Improvements**
* Activity views clarify automatic retries and actions, and show
reviewer names for admins.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
splitsec2 authored and GitHub committed 2026-11-09 12:02:21 -06:00
1 parent be803ed5ca
commit e575ff0fcb
34 files changed
+1774 -138

No files matched your search

+109
View File
@@ -2155,3 +2155,112 @@ def test_reopen_rejected_request_returns_none_for_unknown_or_other_states(user_d
book_data=_book_data(),
)
assert user_db.reopen_rejected_request(created["id"]) is None
def test_rejected_request_can_be_hidden_and_shown_again(user_db):
_alice, _admin, created = _rejected_request(user_db)
assert user_db.set_rejected_request_hidden(created["id"], hidden=True) is True
assert user_db.set_rejected_request_hidden(created["id"], hidden=True) is True
assert user_db.list_hidden_rejected_request_ids() == [created["id"]]
assert user_db.set_rejected_request_hidden(created["id"], hidden=False) is True
assert user_db.list_hidden_rejected_request_ids() == []
def test_only_a_rejected_request_can_be_hidden(user_db):
alice = user_db.create_user(username="alice")
created = create_request(
user_db,
user_id=alice["id"],
source_hint="prowlarr",
content_type="ebook",
request_level="book",
policy_mode="request_book",
book_data=_book_data(),
)
assert user_db.set_rejected_request_hidden(created["id"], hidden=True) is False
assert user_db.list_hidden_rejected_request_ids() == []
def test_reopen_clears_hidden_so_a_later_rejection_starts_visible(user_db):
_alice, admin, created = _rejected_request(user_db)
user_db.set_rejected_request_hidden(created["id"], hidden=True)
reopen_request(user_db, request_id=created["id"], admin_user_id=admin["id"])
reject_request(user_db, request_id=created["id"], admin_user_id=admin["id"])
assert user_db.list_hidden_rejected_request_ids() == []
def _fulfilled_request(user_db, *, delivery_state):
alice = user_db.create_user(username="alice")
admin = user_db.create_user(username="admin", role="admin")
created = create_request(
user_db,
user_id=alice["id"],
source_hint="prowlarr",
content_type="audiobook",
request_level="release",
policy_mode="request_release",
book_data=_book_data(),
release_data=_release_data(),
)
fulfil_request(
user_db,
request_id=created["id"],
admin_user_id=admin["id"],
queue_release=lambda *a, **kw: (True, None),
)
user_db.update_request(created["id"], delivery_state=delivery_state)
return created["id"], admin
@pytest.mark.parametrize("delivery_state", ["cancelled", "error"])
def test_reopen_request_reopens_a_fulfilled_request_whose_download_failed(user_db, delivery_state):
request_id, admin = _fulfilled_request(user_db, delivery_state=delivery_state)
reopened = reopen_request(
user_db, request_id=request_id, admin_user_id=admin["id"], admin_note="[auto] retry"
)
assert reopened["status"] == "pending"
assert reopened["delivery_state"] == "none"
assert reopened["release_data"] is None
assert reopened["admin_note"] == "[auto] retry"
assert reopened["last_failure_reason"] == "[auto] retry"
# The next automatic search skips the release that failed, as when the queue reopens it.
assert reopened["book_data"]["failed_releases"] == [
{"source": "prowlarr", "source_id": "release-123"}
]
def test_reopen_request_writes_the_note_in_the_reopening_write(user_db, monkeypatch):
"""A failed-download reopen never lands without its note: there is no second update."""
request_id, admin = _fulfilled_request(user_db, delivery_state="error")
def no_second_write(*_args, **_kwargs):
msg = "admin_note must be written by reopen_failed_request"
raise AssertionError(msg)
monkeypatch.setattr(user_db, "update_request", no_second_write)
reopened = reopen_request(
user_db, request_id=request_id, admin_user_id=admin["id"], admin_note="Try again"
)
assert reopened["status"] == "pending"
assert reopened["admin_note"] == "Try again"
@pytest.mark.parametrize("delivery_state", ["complete", "queued"])
def test_reopen_request_refuses_a_fulfilled_request_that_is_delivered_or_in_flight(
user_db, delivery_state
):
request_id, admin = _fulfilled_request(user_db, delivery_state=delivery_state)
with pytest.raises(RequestServiceError) as exc_info:
reopen_request(user_db, request_id=request_id, admin_user_id=admin["id"])
assert exc_info.value.code == "stale_transition"
assert user_db.get_request(request_id)["status"] == "fulfilled"