2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-11 15:34:15 +00:00

Check user permissions before linking or un-linking barcodes (#3772)

* Check user permissions before linking or un-linking barcodse

* Bump API version

* Permission fixes for unit tests

* Fix permission issues

* Unit test fixes
This commit is contained in:
Oliver
2022-10-13 12:14:36 +11:00
committed by GitHub
parent fccbcad63f
commit 99d822ecdb
4 changed files with 60 additions and 2 deletions

View File

@ -125,6 +125,19 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
self.assertIn('Missing data:', str(response.data))
# Permission error check
response = self.assign(
{
'barcode': 'abcdefg',
'part': 1,
'stockitem': 1,
},
expected_code=403
)
self.assignRole('part.change')
self.assignRole('stock.change')
# Provide too many fields
response = self.assign(
{
@ -188,6 +201,8 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
barcode = 'xyz-123'
self.assignRole('part.change')
# Test that an initial scan yields no results
response = self.scan(
{
@ -196,6 +211,8 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
expected_code=400
)
self.assignRole('part.change')
# Attempt to assign to an invalid part ID
response = self.assign(
{
@ -247,6 +264,8 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
self.assertIn('Barcode matches existing item', str(response.data['error']))
self.assignRole('part.change')
# Now test that we can unassign the barcode data also
response = self.unassign(
{
@ -265,6 +284,17 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
barcode = '555555555555555555555555'
# Assign random barcode data to a StockLocation instance
response = self.assign(
data={
'barcode': barcode,
'stocklocation': 1,
},
expected_code=403,
)
self.assignRole('stock_location.change')
# Assign random barcode data to a StockLocation instance
response = self.assign(
data={