@@ -363,26 +363,26 @@ def validate(self, data):
363
363
"""
364
364
Validate the ACLExtendedRule django model's inputs before allowing it to update the instance:
365
365
- Check if action set to remark, but no remark set.
366
- - Check if action set to remark, but source_prefix set.
366
+ - Check if action set to remark, but source set.
367
367
- Check if action set to remark, but source_ports set.
368
- - Check if action set to remark, but destination_prefix set.
369
368
- Check if action set to remark, but destination_ports set.
370
369
- Check if action set to remark, but protocol set.
371
- - Check if action set to remark, but protocol set.
370
+ - Check not more than one source is set.
372
371
"""
373
372
error_message = {}
374
373
374
+ sources = ["source_prefix" , "source_iprange" , "source_ipaddress" , "source_aggregate" , "source_service" ]
375
+
375
376
if data .get ("action" ) == "remark" :
376
377
# Check if action set to remark, but no remark set.
377
378
if data .get ("remark" ) is None :
378
379
error_message ["remark" ] = [
379
380
error_message_no_remark ,
380
381
]
381
- # Check if action set to remark, but source_prefix set.
382
- if data .get ("source_prefix" ):
383
- error_message ["source_prefix" ] = [
384
- error_message_action_remark_source_prefix_set ,
385
- ]
382
+ # Check if action set to remark, but source set.
383
+ if any (data .get (source ) for source in sources ):
384
+ for source in sources :
385
+ error_message [source ] = [error_message_action_remark_source_set ]
386
386
# Check if action set to remark, but source_ports set.
387
387
if data .get ("source_ports" ):
388
388
error_message ["source_ports" ] = [
@@ -403,6 +403,12 @@ def validate(self, data):
403
403
error_message ["protocol" ] = [
404
404
"Action is set to remark, Protocol CANNOT be set." ,
405
405
]
406
+
407
+ # Check not more than one source is set.
408
+ if sum (bool (data .get (source )) for source in sources ) > 1 :
409
+ for source in sources :
410
+ error_message [source ] = [error_message_sources_more_than_one ]
411
+
406
412
407
413
if error_message :
408
414
raise serializers .ValidationError (error_message )
0 commit comments