@@ -363,26 +363,26 @@ def validate(self, data):
363363 """
364364 Validate the ACLExtendedRule django model's inputs before allowing it to update the instance:
365365 - 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.
367367 - Check if action set to remark, but source_ports set.
368- - Check if action set to remark, but destination_prefix set.
369368 - Check if action set to remark, but destination_ports set.
370369 - 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.
372371 """
373372 error_message = {}
374373
374+ sources = ["source_prefix" , "source_iprange" , "source_ipaddress" , "source_aggregate" , "source_service" ]
375+
375376 if data .get ("action" ) == "remark" :
376377 # Check if action set to remark, but no remark set.
377378 if data .get ("remark" ) is None :
378379 error_message ["remark" ] = [
379380 error_message_no_remark ,
380381 ]
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 ]
386386 # Check if action set to remark, but source_ports set.
387387 if data .get ("source_ports" ):
388388 error_message ["source_ports" ] = [
@@ -403,6 +403,12 @@ def validate(self, data):
403403 error_message ["protocol" ] = [
404404 "Action is set to remark, Protocol CANNOT be set." ,
405405 ]
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+
406412
407413 if error_message :
408414 raise serializers .ValidationError (error_message )
0 commit comments