Skip to content

[bug] Require only 'view' permission to read model metadata - #13348

Merged
SchrodingersGat merged 1 commit into
inventree:masterfrom
LeonKie:fix/metadata-read-permission
Nov 23, 2026
Merged

SchrodingersGat merged 1 commit into
inventree:masterfrom
LeonKie:fix/metadata-read-permission

Conversation

@LeonKie

@LeonKie LeonKie commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Reading an object's metadata through the generic metadata endpoint (GET /api/metadata/<model>/<pk>/) requires change permission for models without a check_permission() method, e.g. Part or StockItem. A user or API token with only view permission on Parts gets:

HTTP 403 {"detail":"You do not have permission to perform this action."}

although the same user can read the part itself on its detail endpoint. Read-only integrations (e.g. a read-only CI token that compares metadata) therefore need write permission.

Cause

ContentTypePermission.has_object_permission works out the required permission ('view' for safe methods, 'change' otherwise) and passes it to check_permission(), but its fallback for models without one still passes a hardcoded 'change':

return users.permissions.check_user_permission(
    request.user, model_class, 'change'
)

Fix

Pass the computed permission instead, so reads need view and writes still need change. The behaviour for ignore-listed models and models with check_permission() is unchanged.

I did not bump INVENTREE_API_VERSION; happy to add an entry if you consider this an API change.

ContentTypePermission works out 'view' for safe methods and 'change'
otherwise, but its fallback for models without check_permission()
(e.g. Part, StockItem) still passed a hardcoded 'change'. Reading
metadata via the generic metadata endpoint therefore required 'change'
permission, unlike the model's own detail endpoint, which needs 'view'.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@netlify

netlify Bot commented Nov 23, 2026

Copy link
Copy Markdown

👷 Deploy request for inventree-web-pui-preview pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c788e43

@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed api Relates to the API backport Apply this label to a PR to enable auto-backport action backport-to-1.7.x Apply this label to backport a PR to the 1.7.x branch labels Nov 23, 2026
@SchrodingersGat SchrodingersGat added this to the 1.8.0 milestone Nov 23, 2026
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.41%. Comparing base (629a411) to head (c788e43).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13348   +/-   ##
=======================================
  Coverage   90.41%   90.41%           
=======================================
  Files         907      907           
  Lines       83834    83844   +10     
  Branches     4308     4308           
=======================================
+ Hits        75795    75808   +13     
+ Misses       7025     7022    -3     
  Partials     1014     1014           
Flag Coverage Δ
backend 93.93% <100.00%> (+<0.01%) ⬆️

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

Components Coverage Δ
Backend Apps 94.36% <100.00%> (+<0.01%) ⬆️
Backend General 95.01% <100.00%> (+<0.01%) ⬆️
Frontend 77.51% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SchrodingersGat
SchrodingersGat merged commit 3744e74 into inventree:master Nov 23, 2026
46 of 47 checks passed
@SchrodingersGat

Copy link
Copy Markdown
Member

@LeonKie thanks for the fix!

@github-actions

Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
✅ 1.7.x

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

SchrodingersGat pushed a commit that referenced this pull request Nov 24, 2026
…13350)

ContentTypePermission works out 'view' for safe methods and 'change'
otherwise, but its fallback for models without check_permission()
(e.g. Part, StockItem) still passed a hardcoded 'change'. Reading
metadata via the generic metadata endpoint therefore required 'change'
permission, unlike the model's own detail endpoint, which needs 'view'.


(cherry picked from commit 3744e74)

Co-authored-by: Leon Kiesgen <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Relates to the API backport Apply this label to a PR to enable auto-backport action backport-to-1.7.x Apply this label to backport a PR to the 1.7.x branch bug Identifies a bug which needs to be addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants