Skip to content

fix: interactive search from My Requests picks for that request - #463

Merged
kikootwo merged 5 commits into
mainfrom
fix/281-interactive-search-existing-request
Oct 27, 2026
Merged

kikootwo merged 5 commits into
mainfrom
fix/281-interactive-search-existing-request

Conversation

@kikootwo

@kikootwo kikootwo commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #281

Includes the change from #291 by @zpersichetti (re-implemented here with tighter tests; credited in the squash commit).

What changed

  • My Requests: RequestCard now passes the request id, owner and type to AudiobookDetailsModal, the same way the search page and admin panel already do. Interactive Search on an own pending/failed/awaiting_search/awaiting_release audiobook request picks for that request through select-torrent.
  • Ebook requests: the details modal's Interactive Search on an ebook request opens the ebook search. On an own pending/failed/awaiting_search ebook request it searches and picks for that request (requests/[id]/interactive-search-ebook + select-ebook); in other statuses it searches by ASIN.
  • requests/[id]/interactive-search-ebook and requests/[id]/select-ebook were admin-only. They now accept the request's owner or an admin; another user gets 403, and interactive search access is required, as on the other pick routes. A non-admin pick follows the approval settings (new resolveAutoApprove() in src/lib/utils/permissions.ts): if approval is needed, the ebook request goes to awaiting_approval with the pick stored, and the admin approve already handles that. select-ebook also works for an ebook request with no parent audiobook request (a book that was in the library before RMAB requested it). A non-admin may only pass their own ebook request to select-ebook (an audiobook request id is 403), and a user's auto-approved pick sends the request_approved notification, as the by-ASIN route and select-torrent do. Both routes answer 404 for a deleted request (or a deleted parent), for the owner and an admin alike.
  • Details modal: when an ebook pick needs approval, the toast says "Ebook request submitted for approval!" instead of "Ebook download started!" (InteractiveTorrentSearchModal passes needsApproval to onSuccess).
  • request-with-torrent (from Fix misleading "already requested" error on in-progress downloads #291): a book whose request is downloading, processing, awaiting_import or downloaded answers BeingProcessed, and awaiting_approval answers AwaitingApproval, instead of falling through to "You have already requested this audiobook". The "already available" replies no longer name a media server.
  • request-with-torrent: a pick is refused with AlreadyRequested ("This audiobook is already being requested by another user") when another user has an open request for the book, so it can't start a second download. Failed, warn, cancelled and denied requests are ignored by this check. The approval check now uses resolveAutoApprove() (same rule as before).
  • Docs: admin-features/request-approval.md (409 table, select-ebook section, Fixed Issues Fix login and Plex setup flow issues #2), integrations/ebook-sidecar.md, frontend/components.md.

Why

My Requests opened the book details without the request id, so a pick went down the create-new-request path and hit the duplicate check. From the admin panel the same pick went to the existing request. Ebook requests had no way through at all for non-admins, because both request-based ebook routes required an admin.

Evidence

  • tests/api/request-with-torrent-existing-requests.routes.test.ts fakes the request table so each query only sees the rows its where would match: a route that skips a check creates a request. Covers own in-flight requests by status (Fix misleading "already requested" error on in-progress downloads #291), another user's in-flight and open requests, the library wording, and that failed, cancelled and denied requests are ignored.
  • tests/api/requests-pick-existing-request.routes.test.ts: the owner's ebook pick restarts that ebook request and creates none; another user gets 403 with nothing changed; an owner who needs approval gets awaiting_approval with the pick stored and no download; an admin can pick for an ebook request with no parent; a user's audiobook request id is 403 while an admin can still pick for it; a user's auto-approved pick sends request_approved and an admin's sends nothing; a deleted ebook request, a deleted audiobook request and an ebook request with a deleted parent answer 404 for owner and admin with nothing updated, created or started; the owner can run the ebook search and another user can't, and nobody can on a deleted request; select-torrent updates the owner's audiobook request and refuses another user.
  • Component tests: RequestCard passes id, owner and type for audiobook and ebook requests; AudiobookDetailsModal sends an ebook request to the ebook search with the request id only for an own advanceable status, and its toast follows needsApproval.
  • interactive-search-access.test.ts now also covers both request-based ebook routes.
  • With main's source (f5b0543) and this branch's tests: 39 failed, 77 passed. 37 fail on assertions and 2 on a mock error: the two interactive-search-access.test.ts rows for the request-based ebook routes fail on main with No "requireAdmin" export is defined on the auth mock, because those routes were admin-only there. Of Fix misleading "already requested" error on in-progress downloads #291's own three tests, two passed on main because the mock returned the row whatever the query asked for; the new fake fails on main for all of those statuses. On this branch: 116/116 pass.
  • Review fixes (deleted requests, audiobook id from a user, request_approved, approval toast): with the source before those fixes, 10 of the 13 new tests fail; the 3 that pass check unchanged behaviour (an admin's pick sends no notification, an admin can still pick for an audiobook request, the toast without approval).

Checks

  • Unit tests for the changed code (vitest related on the 8 changed source files, plus the new test files): PASS, 29 files, 313/313; after the review fixes, vitest related on the 5 files they touch plus their tests: PASS, 19 files, 199/199
  • Type check and lint: PASS (tsc --noEmit clean; ESLint finds nothing new in the touched files compared with main, and the two new test files are clean)
  • Image build and E2E smoke (rmab-e2e/t48:2474b87, and after the review fixes rmab-e2e/t61:07ff88c): PASS, 1/1 each
  • After merging main (dad0daf): vitest related on the source changed on both sides: 115 files, 1490 passed and 3 timed out under load in two page tests this change does not touch; those two files alone: PASS, 14/14. tsc --noEmit clean
  • Full unit suite: PR Tests (CI)

Risk and rollback

  • Ownership: the two ebook routes now accept a non-admin, but only for their own request, after the interactive search permission check; another user's request is 403 before any search or link lookup. API tokens still cannot call these routes.
  • Approval: a non-admin's ebook pick now goes through the same approval rule as other picks, and sends request_approved when it skips approval. Admin behaviour is unchanged (no approval, no notification).
  • request-with-torrent refuses more picks: in-flight requests and another user's open request. A plain request already refused another user's open request. One difference: the pick ignores another user's denied request, while a plain request still counts it.
  • A pick on a pending ebook request can race the automatic search already queued for it: that search sets searching without a status check, so it can overwrite awaiting_approval or start a second download. Same race as the shipped audiobook pending routing and the admin path on main; not changed here.
  • Behaviour outside My Requests: the search page and admin panel already passed the request id, so their routing is unchanged.
  • Rollback: revert this PR. No schema or data changes.

Release note

🤖 Generated with Claude Code

kikootwo and others added 5 commits October 27, 2026 01:37
My Requests opened the book details without the request id, so a pick
went down the create-new-request path and was refused as already
requested. The card now passes the request id, owner and type; an ebook
request searches ebook sources for that request.

- requests/[id]/interactive-search-ebook and select-ebook accept the
  request owner as well as admins (another user gets 403); a non-admin
  pick follows the approval settings
- select-ebook works for an ebook request with no parent audiobook request
- request-with-torrent says what is happening when the book is already
  downloading, processing or awaiting approval (#291), and refuses a pick
  that would open a second request next to another user's open request

Co-authored-by: zpersichetti <17482716+zpersichetti@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…281)

- select-ebook and interactive-search-ebook answer 404 for a deleted
  request (and a deleted parent), for owner and admin alike.
- A non-admin may only pick for an ebook request in select-ebook.
- A user's auto-approved ebook pick sends the request_approved notification.
- The ebook pick toast says the pick was sent for approval when it was.
- request-with-torrent uses resolveAutoApprove() for its approval check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…#281)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interactive search on existing request tries to create new request for same book, fails (is blocked) because book is already requested

1 participant