[API] Optional field permissions - #12529
Merged
SchrodingersGat merged 13 commits intoAug 3, 2026
Merged
Conversation
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
SchrodingersGat
marked this pull request as draft
August 1, 2026 01:46
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the REST API’s OptionalField mechanism to avoid leaking cross-model “detail” data (nested serializers) when the requesting user lacks view permission for the embedded model, aligning optional output expansion with the permission system.
Changes:
- Add embedded-model view-permission gating (with per-request caching) to
OptionalFieldinclusion logic. - Update and extend API/unit tests to reflect permission-gated optional fields and adjust required test roles.
- Document the breaking behavior change in the changelog.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/backend/InvenTree/InvenTree/serializers.py | Enforces view-permission checks for optional fields that embed other models, with caching and exemptions for permission-metadata models. |
| src/backend/InvenTree/InvenTree/test_serializers.py | Adds a unit test verifying permission-gating behavior for an OptionalField which embeds a model. |
| src/backend/InvenTree/stock/test_api.py | Adds a stock API test covering part_detail visibility based on part-view permissions. |
| src/backend/InvenTree/part/test_api.py | Updates roles and expectations/comments to accommodate permission-gated optional embedded fields and query-count impact. |
| src/backend/InvenTree/order/test_api.py | Expands test roles to include view permissions required for newly gated embedded relations. |
| src/backend/InvenTree/company/test_api.py | Adjusts test roles to include additional view permission needed due to embedded-field gating. |
| CHANGELOG.md | Notes the breaking change: related detail fields are removed when the user lacks view permission. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12529 +/- ##
==========================================
+ Coverage 86.71% 86.75% +0.04%
==========================================
Files 1445 1445
Lines 96288 96340 +52
Branches 11229 11229
==========================================
+ Hits 83498 83583 +85
+ Misses 12726 12693 -33
Partials 64 64
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
SchrodingersGat
marked this pull request as ready for review
August 2, 2026 19:47
matmair
approved these changes
Aug 3, 2026
Lowkey-wizard
added a commit
to EQUA-AI/InvenTree
that referenced
this pull request
Aug 7, 2026
Post-migration deploy verifier for the 2026-08 upstream sync: duplicate (part, serial) audit mirroring stock/0126's partial-index condition, pending-migration report, and inventree#12529 role-coverage audit for the AI service token account and technician groups. Grants are opt-in flags, idempotent, and never downgrade. Tests pin the token-authenticated detail-field contract on the stock list - the coverage gap that let the inventree#12529 narrowing go undetected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
OptionalFields expose cross-model relations without checking that the user has the correct permissions for the related models.
This PR excludes OptionalFields if the user does not have view permission for the associated model