2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-05-22 01:06:50 +00:00

realign user API endpoints (#11963)

* realign user API endpoints to make it clearer which one are only applicable to the current user

* fix name

* bump api

* fix test

* fix reference

* fix test exception

* update ref

* reduce breakage

* re-add legacy urls till next `breaking`
This commit is contained in:
Matthias Mair
2026-05-22 01:44:24 +02:00
committed by GitHub
parent f27b9b5443
commit 9908870a81
12 changed files with 72 additions and 17 deletions
@@ -1,11 +1,14 @@
"""InvenTree API version information."""
# InvenTree API version
INVENTREE_API_VERSION = 489
INVENTREE_API_VERSION = 490
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """
v490 -> 2026-05-19 : https://github.com/inventree/InvenTree/pull/11963
- moves user-self-filtered endpoints to /user/me/ to make their security boundaries clearer
v489 -> 2026-05-18 : https://github.com/inventree/InvenTree/pull/11962
- Removes the "remote_image" field from the Part API endpoint
- Removes the "remote_image" field from the Company API endpoint
+21
View File
@@ -341,3 +341,24 @@ def schema_for_view_output_options(view_class):
view_class
)
return extended_view
def exclude_from_schema(klass: type, alternative_path: str) -> type:
"""Decorator to exclude a view from the OpenAPI schema.
This is used to hide legacy endpoints from the schema, while still retaining them for backwards compatibility.
"""
class LegacyView(klass):
"""Dummy doc."""
LegacyView.__name__ = klass.__name__ + ' - Legacy'
LegacyView.__doc__ = f'This is a legacy endpoint, retained for backwards compatibility. Consider migrating to the new endpoint under {alternative_path}.'
# Exclude all default operations from the schema
for operation in ['get', 'post', 'put', 'patch', 'delete']:
if hasattr(klass, operation):
LegacyView = extend_schema_view(**{operation: extend_schema(exclude=True)})(
LegacyView
)
return LegacyView
+33 -4
View File
@@ -33,6 +33,7 @@ from InvenTree.mixins import (
SerializerContextMixin,
UpdateAPI,
)
from InvenTree.schema import exclude_from_schema
from InvenTree.settings import FRONTEND_URL_BASE
from users.models import ApiToken, Owner, RuleSet, UserProfile
from users.serializers import (
@@ -501,8 +502,38 @@ class UserProfileDetail(RetrieveUpdateAPI):
user_urls = [
path('roles/', RoleDetails.as_view(), name='api-user-roles'),
path('token/', ensure_csrf_cookie(GetAuthToken.as_view()), name='api-token'),
# Legacy endpoints (to avoid breaking existing API clients)
# TODO @matmair - remove these legacy endpoints in the next breaking release
path(
'roles/',
exclude_from_schema(RoleDetails, '/api/user/me/roles/').as_view(),
name='api-user-roles_legacy',
),
path(
'token/',
ensure_csrf_cookie(
exclude_from_schema(GetAuthToken, '/api/user/me/token/').as_view()
),
name='api-token_legacy',
),
path(
'profile/',
exclude_from_schema(UserProfileDetail, '/api/user/me/profile/').as_view(),
name='api-user-profile_legacy',
),
# Individual user endpoints
path(
'me/',
include([
path('profile/', UserProfileDetail.as_view(), name='api-user-profile'),
path('roles/', RoleDetails.as_view(), name='api-user-roles'),
path(
'token/', ensure_csrf_cookie(GetAuthToken.as_view()), name='api-token'
),
path('', MeUserDetail.as_view(), name='api-user-me'),
]),
),
# User related endpoints
path(
'tokens/',
include([
@@ -510,8 +541,6 @@ user_urls = [
path('', TokenListView.as_view(), name='api-token-list'),
]),
),
path('me/', MeUserDetail.as_view(), name='api-user-me'),
path('profile/', UserProfileDetail.as_view(), name='api-user-profile'),
path(
'owner/',
include([