Return 404 before 403 for order status updates - #49
Merged
Conversation
Move the business-user gate to object level so a PATCH on a non-existent order surfaces a 404 instead of a 403 for non-business users, matching the documented status codes.
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.
Problem
A
PATCH /api/orders/{id}/on a non-existent order returned 403 instead of 404 for non-business users (customers / users without a profile). This was the single issue flagged in the mentor's acceptance review.Root cause:
IsBusinessUserwas a view-level permission (has_permission), which DRF evaluates ininitial()beforeget_object()runs. So a non-business user hit the 403 gate before the object lookup could raise the 404.The existing test only covered the business-user case (which already returned 404), so the gap slipped through.
Fix
IsBusinessUser()from the update permissions; rely on the object-levelIsOrderBusinessOwner(). Nowget_object()(404) runs before the owner check (403).IsBusinessUserclass and import fromorders_app.Behavior (now matches
docs/endpoints.md)Tests
179 passed (was 178), coverage 98.26%, ruff clean.