@@ -356,26 +356,26 @@ def validate(self, data):
356
356
"""
357
357
Validate the ACLExtendedRule django model's inputs before allowing it to update the instance:
358
358
- Check if action set to remark, but no remark set.
359
- - Check if action set to remark, but source_prefix set.
359
+ - Check if action set to remark, but source set.
360
360
- Check if action set to remark, but source_ports set.
361
- - Check if action set to remark, but destination_prefix set.
362
361
- Check if action set to remark, but destination_ports set.
363
362
- Check if action set to remark, but protocol set.
364
- - Check if action set to remark, but protocol set.
363
+ - Check not more than one source is set.
365
364
"""
366
365
error_message = {}
367
366
367
+ sources = ["source_prefix" , "source_iprange" , "source_ipaddress" , "source_aggregate" , "source_service" ]
368
+
368
369
if data .get ("action" ) == "remark" :
369
370
# Check if action set to remark, but no remark set.
370
371
if data .get ("remark" ) is None :
371
372
error_message ["remark" ] = [
372
373
error_message_no_remark ,
373
374
]
374
- # Check if action set to remark, but source_prefix set.
375
- if data .get ("source_prefix" ):
376
- error_message ["source_prefix" ] = [
377
- error_message_action_remark_source_prefix_set ,
378
- ]
375
+ # Check if action set to remark, but source set.
376
+ if any (data .get (source ) for source in sources ):
377
+ for source in sources :
378
+ error_message [source ] = [error_message_action_remark_source_set ]
379
379
# Check if action set to remark, but source_ports set.
380
380
if data .get ("source_ports" ):
381
381
error_message ["source_ports" ] = [
@@ -396,6 +396,12 @@ def validate(self, data):
396
396
error_message ["protocol" ] = [
397
397
"Action is set to remark, Protocol CANNOT be set." ,
398
398
]
399
+
400
+ # Check not more than one source is set.
401
+ if sum (bool (data .get (source )) for source in sources ) > 1 :
402
+ for source in sources :
403
+ error_message [source ] = [error_message_sources_more_than_one ]
404
+
399
405
400
406
if error_message :
401
407
raise serializers .ValidationError (error_message )
0 commit comments