Skip to content

[api] Role permission tweaks - #13243

Closed
SchrodingersGat wants to merge 17 commits into
inventree:masterfrom
SchrodingersGat:role-permission-fail-open
Closed

SchrodingersGat wants to merge 17 commits into
inventree:masterfrom
SchrodingersGat:role-permission-fail-open

Conversation

@SchrodingersGat

@SchrodingersGat SchrodingersGat commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

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

  • Address incorrect BOM action permissions following addition of new role
  • Better exception handling during role checks
  • Add explicit role requirements to stock adjustment endpoints
  • Extend permission-based checks to cover oauth token scopes
  • additional documentation around role based permission checking

- Address incorrect BOM action permissions following addition of new role
- Better exception handling during role checks
- Add explicit role requirements to stock adjustment endpoints
@SchrodingersGat SchrodingersGat added this to the 1.8.0 milestone Nov 10, 2026
@SchrodingersGat SchrodingersGat added the api Relates to the API label Nov 10, 2026
@netlify

netlify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit ba13975
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6afce62839ca3e274e898395

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.84906% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.41%. Comparing base (c79acc3) to head (ba13975).
⚠️ Report is 3 commits behind head on master.

❌ 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     
Flag Coverage Δ
backend 93.95% <95.84%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 94.41% <91.56%> (+<0.01%) ⬆️
Backend General 95.44% <77.41%> (-0.05%) ⬇️
Frontend 77.35% <ø> (-0.03%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SchrodingersGat SchrodingersGat added security Relates to a security issue documentation labels Nov 10, 2026
@matmair matmair added the breaking Indicates a major update or change which breaks compatibility label Nov 13, 2026
@inventree inventree deleted a comment from coderabbitai Bot Nov 15, 2026
@matmair

matmair commented Nov 17, 2026

Copy link
Copy Markdown
Member

@SchrodingersGat is this ready for merge?

@SchrodingersGat

Copy link
Copy Markdown
Member Author

Replaced by #13410

@SchrodingersGat
SchrodingersGat deleted the role-permission-fail-open branch November 29, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Relates to the API breaking Indicates a major update or change which breaks compatibility documentation security Relates to a security issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants