fix(request): correct delete permission check and await movie save#2742
fix(request): correct delete permission check and await movie save#2742dougrathbone wants to merge 1 commit intoseerr-team:developfrom
Conversation
Two bugs in the request route handler: 1. DELETE /request/:id used three top-level && conditions to gate deletion, meaning any authenticated user could delete any PENDING request because the third condition (status !== PENDING) short-circuits the denial. The intent is: non-admins may only retract their own requests while they are still pending. Fixed by grouping the ownership and status checks with || inside a single outer && against the admin check. Before: !admin && !owner && !pending (allows deletion if pending) After: !admin && (!owner || !pending) (owner + pending required) Also replaces the magic number 1 with MediaRequestStatus.PENDING. 2. The movie branch of PUT /request/:id called requestRepository.save() without await, returning the 200 response before the write completed. The TV branch in the same handler correctly awaits the save. Fixed by adding the missing await. Tests cover: owner can delete own pending request, admin can delete any request, non-owner non-admin is denied on a pending request, owner is denied on an approved request, and movie update changes are persisted before the response is returned.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughA new comprehensive test file validates request route handlers ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
Two bugs in
server/routes/request.ts:1. Anyone can delete any pending request
The
DELETE /request/:idhandler used three top-level&&conditions to gate deletion:Because all three must be true to deny, the third condition short-circuits the check whenever a request is
PENDING-- meaning any authenticated user can delete any pending request they did not create. The intended behaviour is that non-admins may only retract their own requests while they are still pending.Also replaces the magic number
1withMediaRequestStatus.PENDING.2. Movie request update is not awaited
The movie branch of
PUT /request/:idcalledrequestRepository.save()withoutawait, returning the200response before the write completed. The TV branch in the same handler correctly awaits the save.How Has This Been Tested?
pnpm test-- 30/30 tests pass including a newserver/routes/request.test.tssuite covering:Screenshots / Logs (if applicable)
Checklist:
pnpm buildpnpm i18n:extractAI was used for code completion. All testing and interaction with the codebase was done manually.
Summary by CodeRabbit