Repository navigation
[api] Role permission tweaks - #13243
SchrodingersGat wants to merge 17 commits into
Conversation
- Address incorrect BOM action permissions following addition of new role - Better exception handling during role checks - Add explicit role requirements to stock adjustment endpoints
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
There was a problem hiding this comment.
🟡 Changes recommended
BOM-creation-only OAuth2 tokens can delete existing rows without a delete scope when their owner has delete permission, and the permission audit can miss unresolved views.
2 open issues
What changed in this PR
This PR tightens role-based authorization for InvenTree API actions, particularly BOM copying and stock adjustments.
Changes:
- Adds explicit BOM and stock role requirements, including conditional permission to delete existing BOM items.
- Improves permission-model resolution and denies writes when no model can be resolved.
- Adds permission regression tests and documents the breaking changes in API version 575.
| File | Description |
|---|---|
src/backend/InvenTree/stock/test_api.py |
Tests stock action permissions and unchanged data after denial. |
src/backend/InvenTree/stock/api.py |
Requires stock.change for stock actions. |
src/backend/InvenTree/part/test_api.py |
Tests BOM copy permissions and OPTIONS metadata. |
src/backend/InvenTree/part/serializers.py |
Checks delete permission when replacing BOM items. |
src/backend/InvenTree/part/api.py |
Requires bom.add for BOM copying. |
src/backend/InvenTree/InvenTree/test_permissions.py |
Adds permission-resolution tests and a writable-view audit. |
src/backend/InvenTree/InvenTree/permissions.py |
Refines model discovery, role parsing, and write-denial behavior. |
src/backend/InvenTree/InvenTree/metadata.py |
Handles unresolved models and explicit role requirements. |
src/backend/InvenTree/InvenTree/api_version.py |
Bumps the API version and records permission changes. |
src/backend/InvenTree/build/test_api.py |
Tests role enforcement for build actions. |
Review effort: Balanced
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (77.41%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #13243 +/- ##
==========================================
+ Coverage 90.36% 90.41% +0.05%
==========================================
Files 901 902 +1
Lines 83650 84122 +472
Branches 4300 4300
==========================================
+ Hits 75590 76061 +471
+ Misses 7045 7044 -1
- Partials 1015 1017 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…mission-fail-open
|
@SchrodingersGat is this ready for merge? |
|
Replaced by #13410 |


Multiple tweaks / improvements to role permission checks against API endpoints: