mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Prevent assigning of empty barcode data (#3851)
* Prevent assigning of empty barcode data * Make similar check for barcode scan endpoint * Fixes for unit tests
This commit is contained in:
parent
824a44a486
commit
13cfadaf29
@ -48,8 +48,10 @@ class BarcodeScan(APIView):
|
|||||||
"""
|
"""
|
||||||
data = request.data
|
data = request.data
|
||||||
|
|
||||||
if 'barcode' not in data:
|
barcode_data = data.get('barcode', None)
|
||||||
raise ValidationError({'barcode': _('Must provide barcode_data parameter')})
|
|
||||||
|
if not barcode_data:
|
||||||
|
raise ValidationError({'barcode': _('Missing barcode data')})
|
||||||
|
|
||||||
# Ensure that the default barcode handlers are run first
|
# Ensure that the default barcode handlers are run first
|
||||||
plugins = [
|
plugins = [
|
||||||
@ -57,7 +59,6 @@ class BarcodeScan(APIView):
|
|||||||
InvenTreeExternalBarcodePlugin(),
|
InvenTreeExternalBarcodePlugin(),
|
||||||
] + registry.with_mixin('barcode')
|
] + registry.with_mixin('barcode')
|
||||||
|
|
||||||
barcode_data = data.get('barcode')
|
|
||||||
barcode_hash = hash_barcode(barcode_data)
|
barcode_hash = hash_barcode(barcode_data)
|
||||||
|
|
||||||
# Look for a barcode plugin which knows how to deal with this barcode
|
# Look for a barcode plugin which knows how to deal with this barcode
|
||||||
@ -106,10 +107,10 @@ class BarcodeAssign(APIView):
|
|||||||
|
|
||||||
data = request.data
|
data = request.data
|
||||||
|
|
||||||
if 'barcode' not in data:
|
barcode_data = data.get('barcode', None)
|
||||||
raise ValidationError({'barcode': _('Must provide barcode_data parameter')})
|
|
||||||
|
|
||||||
barcode_data = data['barcode']
|
if not barcode_data:
|
||||||
|
raise ValidationError({'barcode': _('Missing barcode data')})
|
||||||
|
|
||||||
# Here we only check against 'InvenTree' plugins
|
# Here we only check against 'InvenTree' plugins
|
||||||
plugins = [
|
plugins = [
|
||||||
|
@ -55,7 +55,8 @@ class BarcodeAPITest(InvenTreeAPITestCase):
|
|||||||
self.assertEqual(response.status_code, 400)
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
data = response.data
|
data = response.data
|
||||||
self.assertIn('error', data)
|
self.assertIn('barcode', data)
|
||||||
|
self.assertIn('Missing barcode data', str(response.data['barcode']))
|
||||||
|
|
||||||
def test_find_part(self):
|
def test_find_part(self):
|
||||||
"""Test that we can lookup a part based on ID."""
|
"""Test that we can lookup a part based on ID."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user