mirror of
https://github.com/inventree/InvenTree.git
synced 2026-12-03 04:41:52 +00:00
[API] PartThumbs role_required (#13434)
* [API] PartThumbs role_required * Bump API version
This commit is contained in:
1 parent
3b666503a8
commit
682f89fdb8
3 files changed
+40
-1
No files matched your search
@@ -1,11 +1,14 @@
|
||||
"""InvenTree API version information."""
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 588
|
||||
INVENTREE_API_VERSION = 589
|
||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||
|
||||
INVENTREE_API_TEXT = """
|
||||
|
||||
v589 -> 2026-12-02 : https://github.com/inventree/InvenTree/pull/13434
|
||||
- The "PartThumb" API endpoint now requires that the user has the 'part view' role permission
|
||||
|
||||
v588 -> 2026-12-01 : https://github.com/inventree/InvenTree/pull/13430
|
||||
- The "quantity" field for the barcode sales order allocation endpoint must be greater than zero
|
||||
|
||||
|
||||
@@ -457,6 +457,10 @@ class PartThumbs(ListAPI):
|
||||
queryset = Part.objects.all()
|
||||
serializer_class = part_serializers.PartThumbSerializer
|
||||
|
||||
# PartThumbSerializer is not a ModelSerializer,
|
||||
# so the required role must be specified explicitly
|
||||
role_required = 'part'
|
||||
|
||||
def get_queryset(self):
|
||||
"""Return a queryset which excludes any parts without images."""
|
||||
queryset = super().get_queryset()
|
||||
|
||||
@@ -1322,6 +1322,38 @@ class PartAPITest(PartAPITestBase):
|
||||
|
||||
self.get(url)
|
||||
|
||||
def test_thumbs_permission(self):
|
||||
"""The part thumbnail list requires the 'part.view' role."""
|
||||
url = reverse('api-part-thumbs')
|
||||
|
||||
part = Part.objects.get(pk=1)
|
||||
Part.objects.filter(pk=part.pk).update(image='part_images/thumb_perm_test.png')
|
||||
|
||||
def matches(response):
|
||||
"""Return the thumbnail entries which reference the test image."""
|
||||
return [
|
||||
row
|
||||
for row in response.data
|
||||
if 'thumb_perm_test' in str(row.get('image', ''))
|
||||
]
|
||||
|
||||
# With the 'part.view' role, the image is returned (control)
|
||||
response = self.get(url, {'search': part.name}, expected_code=200)
|
||||
self.assertEqual(len(matches(response)), 1)
|
||||
|
||||
# Without any roles, the thumbnail list (and search) is denied
|
||||
self.clearRoles()
|
||||
|
||||
for params in [{}, {'search': part.name}]:
|
||||
response = self.get(url, params, expected_code=403)
|
||||
self.assertNotIn('thumb_perm_test', str(response.data))
|
||||
|
||||
# Restore the 'part.view' role - access is granted again
|
||||
self.assignRole('part.view')
|
||||
|
||||
response = self.get(url, {'search': part.name}, expected_code=200)
|
||||
self.assertEqual(len(matches(response)), 1)
|
||||
|
||||
def test_paginate(self):
|
||||
"""Test pagination of the Part list API."""
|
||||
for n in [1, 5, 10]:
|
||||
|
||||
Reference in new issue
Block a user