Repository navigation
fix: a deleted request no longer accepts a torrent pick or a search - #476
Merged
Merged
Conversation
select-torrent, interactive-search, manual-search and fetch-ebook loaded the request by id only, so a deleted request could still start a download or a search. Each now loads with deletedAt: null, as select-ebook and interactive-search-ebook already do, and a deleted request answers the route's usual 404. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The approve route loaded the request by id only, so approving a request deleted while it awaited approval still queued its search or download. It now loads with deletedAt: null and the same include; a deleted request gets the route's existing 404 for approve and deny. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kikootwo
marked this pull request as ready for review
October 27, 2026 08:13
NichCodes
added a commit
to NichCodes/ReadMeABook
that referenced
this pull request
Nov 2, 2026
Conflict resolutions: - Approve route: kept the thin wrapper around processRequestApproval and moved upstream's route fixes into the shared service, so the Web UI, API tokens and Discord all get them: release-pick validation (guardTorrentSelection/guardEbookSelection, kikootwo#355) in a new request-approval-selection helper, run before the atomic claim, with 503 (source unreachable) and 400 (unusable admin pick) responses and the stored-pick fallback to automatic search; buildEbookDownloadName (kikootwo#478); readJsonBody body limits (kikootwo#438/kikootwo#442). The deleted-request guard (kikootwo#476) was already in the service. - Init route: took upstream's secret-gated POST/runAppInitOnce; the bot still starts once after the first successful init. - users/[id], notifications/test, organize-files: kept both sides. - package.json/lock: upstream versions plus discord.js. Follow-ups for upstream conventions and test changes: - Discord settings routes read bodies through readJsonBody. - Approve tests mock the updateMany claim (the shared Prisma mock now returns { count: 0 } by default).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #470
What changed
POST /api/requests/[id]/select-torrent,/interactive-search,/manual-searchand/fetch-ebookload the request withprisma.request.findFirst({ where: { id, deletedAt: null } })instead offindUnique({ where: { id } }). A deleted request now gets the same 404 body each route already sends for a missing request, for its owner and for admins.fetch-ebookis admin only, so a non-admin owner still gets the admin check's 403.POST /api/admin/requests/[id]/approveloads the request the same way, with the same include. A request deleted while it awaited approval now gets the route's existing 404 for both approve and deny, and none of its jobs are queued.tests/api/requests-deleted-request-routes.test.ts, plus a deleted-request case for approve and deny intests/api/requests-approval.routes.test.ts. Five existing test files (requests-actions.routes,admin-requests.routes,download-selection-guard.routes,notification-triggers.integration,pick-credentials.routes) and the approval test now mockrequest.findFirstfor these routes instead ofrequest.findUnique.documentation/admin-features/request-deletion.md, Fixed Issues Add verbose matching logs to debugging #7.Why
Deleting a request is a soft delete: it sets
deletedAtand keeps the status. These five routes loaded the request by id alone. A deleted request could still have a torrent picked (and a download job queued), an interactive or manual search run, or an ebook request created and searched. An admin could also approve it, which queues its search or download. #463 already fixed the ebook routes (select-ebook,interactive-search-ebook) the same way.Sweep of
src/app/api/requests/[id]/and the jobs these routes queue:GETandPATCHonroute.ts,download,download-token,select-ebook,interactive-search-ebook, andfetch-ebook's lookup of an existing ebook request.DELETEonroute.tshard-deletes by id with no filter. It is admin only and starts nothing, so this PR leaves it.download_torrentandsearch_indexersjobs already skip a cancelled or deleted request (updateRequestUnlessStopped). Notification jobs don't load the request.search_ebookjob (queued bymanual-search,fetch-ebookand approval) has no deleted check of its own. With these routes fixed, none of them queues it for a deleted request any more. This PR leaves the job as is.Evidence
/api/requests/[id]/route with Prisma mocks that apply thewherefields to fixture rows, deleted ones included. Per route: a deleted request gets a 404 with the route's not-found body for the owner and for an admin, and no search runs, no job is queued, and nothing is created or updated. A live request still gets its search or download.main's routes (08dc816) and this branch's test file: 9 failed, 5 passed, all on an assertion (each deleted case got a 200 where it should have got a 404). On this branch: 14/14 pass.where-applying mock. Against the previous branch head (a7d4b2b, approve route unchanged), both failed on an assertion (200 where it should have been 404). On this branch: 2/2 pass, and the request is not updated and no search, download or notification job is queued.Checks
vitest relatedon the four/api/requests/[id]/routes plus the new test file: PASS, 5 files, 85/85; on the approve route plusrequests-approval.routes: PASS, 4 files, 90/90)tsc --noEmitclean; ESLint finds no problems in the new test file, and the other touched files report the same counts as before the change)Risk and rollback
deletedAtset behave differently. A live request is found exactly as before (idis unique, anddeletedAt: nullmatches every live row).Release note
🤖 Generated with Claude Code