@@ -667,34 +667,33 @@ class Meta:
667
667
"description" ,
668
668
)
669
669
help_texts = {
670
- "action" : help_text_acl_action ,
671
- "destination_ports" : help_text_acl_rule_logic ,
672
670
"index" : help_text_acl_rule_index ,
673
- "protocol " : help_text_acl_rule_logic ,
671
+ "action " : help_text_acl_action ,
674
672
"remark" : mark_safe (
675
673
"<b>*Note:</b> CANNOT be set if action is not set to remark." ,
676
674
),
677
675
"source_ports" : help_text_acl_rule_logic ,
676
+ "destination_ports" : help_text_acl_rule_logic ,
677
+ "protocol" : help_text_acl_rule_logic ,
678
678
}
679
679
680
680
def clean (self ):
681
681
"""
682
682
Validates form inputs before submitting:
683
683
- Check if action set to remark, but no remark set.
684
- - Check if action set to remark, but source_prefix set.
685
- - Check if action set to remark, but source_ports set.
686
- - Check if action set to remark, but destination_prefix set.
687
- - Check if action set to remark, but destination_ports set.
688
- - Check if action set to remark, but protocol set.
684
+ - Check if action set to remark, but source set.
685
+ - Check if action set to remark, but protocol set
689
686
- Check remark set, but action not set to remark.
687
+ - Check not more than one source is set.
690
688
"""
691
689
super ().clean ()
692
690
cleaned_data = self .cleaned_data
693
691
error_message = {}
694
692
695
693
action = cleaned_data .get ("action" )
696
694
remark = cleaned_data .get ("remark" )
697
- source_prefix = cleaned_data .get ("source_prefix" )
695
+
696
+ sources = ["source_prefix" , "source_iprange" , "source_ipaddress" , "source_aggregate" , "source_service" ]
698
697
source_ports = cleaned_data .get ("source_ports" )
699
698
destination_prefix = cleaned_data .get ("destination_prefix" )
700
699
destination_ports = cleaned_data .get ("destination_ports" )
@@ -703,8 +702,11 @@ def clean(self):
703
702
if action == "remark" :
704
703
if not remark :
705
704
error_message ["remark" ] = [error_message_no_remark ]
706
- if source_prefix :
707
- error_message ["source_prefix" ] = [error_message_action_remark_source_prefix_set ]
705
+
706
+ # Check if action set to remark, but source set.
707
+ for source in sources :
708
+ error_message [source ] = [error_message_action_remark_source_set ]
709
+
708
710
if source_ports :
709
711
error_message ["source_ports" ] = ["Action is set to remark, Source Ports CANNOT be set." ]
710
712
if destination_prefix :
@@ -716,5 +718,10 @@ def clean(self):
716
718
elif remark :
717
719
error_message ["remark" ] = [error_message_remark_without_action_remark ]
718
720
721
+ # Check not more than one source is set.
722
+ elif sum (bool (cleaned_data .get (source )) for source in sources ) > 1 :
723
+ for source in sources :
724
+ error_message [source ] = [error_message_sources_more_than_one ]
725
+
719
726
if error_message :
720
727
raise ValidationError (error_message )
0 commit comments