Repository navigation
[pull] master from inventree:master - #152
Merged
Merged
Conversation
* Add BOM role * Adjust UI permissions * Adjust docs * Add data migratoin * Specify role for BOM validation * Tweak old migrati * Fix role_required * Update API version and CHANGELOG Co-authored-by: Copilot <copilot@github.com> * Update unit tests Co-authored-by: Copilot <copilot@github.com> --------- Co-authored-by: Copilot <copilot@github.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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )
Greptile Summary
This PR introduces a new
bomruleset that separates Bill of Materials permissions from the broaderpartruleset, adds corresponding frontend role guards, and bumps the API to v481. The approach is sound, but two backend issues need attention before the permission separation works as intended:RULESET_CHANGE_INHERIT = [('part', 'bomitem')]inruleset.pyis not updated, so any user withpart.changestill silently inherits full BOM-item permissions via both thepermissions.pyandtasks.pycode paths — effectively bypassing the newbomrole.0148) imports the liveRuleSetmodel directly instead of usingapps.get_model('users', 'RuleSet'), which is fragile if the model ever changes after this migration is squashed or re-run from scratch.Confidence Score: 3/5
Not safe to merge as-is — the stale RULESET_CHANGE_INHERIT entry means the new bom role separation does not fully take effect, and the migration uses a live model import.
Two P1 findings: stale inheritance silently grants BOM access to part.change holders (defeating the core purpose of this PR), and the migration uses a live model import that is fragile. Frontend and OAuth scope changes are clean.
src/backend/InvenTree/users/ruleset.py (RULESET_CHANGE_INHERIT) and src/backend/InvenTree/part/migrations/0148_auto_20260427_2233.py (live model import)
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[User Request to BOM endpoint] --> B{Has bom role?} B -->|Yes| C[Access Granted via bom ruleset] B -->|No| D{Has part.change via RULESET_CHANGE_INHERIT?} D -->|Yes| E["BOM item access STILL GRANTED ⚠️ stale inheritance"] D -->|No| F[403 Forbidden]Comments Outside Diff (3)
src/backend/InvenTree/users/ruleset.py, line 45 (link)Stale
RULESET_CHANGE_INHERITbypasses new BOM role separationRULESET_CHANGE_INHERIT = [('part', 'bomitem')]still propagates full BOM-item permissions to any user who holdspart.change, via the logic inpermissions.py(line 176-183) andtasks.py(line 177-196). Now thatpart_bomitemandpart_bomitemsubstitutelive exclusively under thebomruleset, this inheritance rule silently grants those permissions topartrole holders, effectively nullifying the new granular separation this PR introduces.src/backend/InvenTree/part/migrations/0148_auto_20260427_2233.py, line 13-15 (link)Migration imports live model instead of historical model
from users.models import RuleSetimports the current live model rather than the frozen historical snapshot that Django provides viaapps.get_model(). If theRuleSetmodel is later renamed, removed, or its fields change, this migration will break when run from scratch. The correct pattern isRuleSet = apps.get_model('users', 'RuleSet')(using theappsparameter already passed toupdate_bom_role). ImportingRuleSetEnumdirectly is acceptable since it is a pure enum with no DB schema dependency, but theRuleSetmodel reference should use the historical registry.src/backend/InvenTree/part/test_api.py, line 1041-1050 (link)Test assigns
bom.addfor a read-only endpointPartValidateBOMis aRetrieveUpdateAPIwithrole_required = 'bom.change'. The test grantsbom.addand immediately does a GET, expecting a 200. Usingaddto satisfy achange-gated GET either accidentally exercises an unintended permission path or is testing the wrong role; the test should assignbom.vieworbom.changeto match the documented requirement. The same pattern appears inBomItemTest(assignRole('bom.add')before a list GET at line ~2932).Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "BOM Ruleset (#11825)" | Re-trigger Greptile