@@ -684,34 +684,33 @@ class Meta:
684
684
)
685
685
686
686
help_texts = {
687
- "action" : help_text_acl_action ,
688
- "destination_ports" : help_text_acl_rule_logic ,
689
687
"index" : help_text_acl_rule_index ,
690
- "protocol " : help_text_acl_rule_logic ,
688
+ "action " : help_text_acl_action ,
691
689
"remark" : mark_safe (
692
690
"<b>*Note:</b> CANNOT be set if action is not set to remark." ,
693
691
),
694
692
"source_ports" : help_text_acl_rule_logic ,
693
+ "destination_ports" : help_text_acl_rule_logic ,
694
+ "protocol" : help_text_acl_rule_logic ,
695
695
}
696
696
697
697
def clean (self ):
698
698
"""
699
699
Validates form inputs before submitting:
700
700
- Check if action set to remark, but no remark set.
701
- - Check if action set to remark, but source_prefix set.
702
- - Check if action set to remark, but source_ports set.
703
- - Check if action set to remark, but destination_prefix set.
704
- - Check if action set to remark, but destination_ports set.
705
- - Check if action set to remark, but protocol set.
701
+ - Check if action set to remark, but source set.
702
+ - Check if action set to remark, but protocol set
706
703
- Check remark set, but action not set to remark.
704
+ - Check not more than one source is set.
707
705
"""
708
706
super ().clean ()
709
707
cleaned_data = self .cleaned_data
710
708
error_message = {}
711
709
712
710
action = cleaned_data .get ("action" )
713
711
remark = cleaned_data .get ("remark" )
714
- source_prefix = cleaned_data .get ("source_prefix" )
712
+
713
+ sources = ["source_prefix" , "source_iprange" , "source_ipaddress" , "source_aggregate" , "source_service" ]
715
714
source_ports = cleaned_data .get ("source_ports" )
716
715
destination_prefix = cleaned_data .get ("destination_prefix" )
717
716
destination_ports = cleaned_data .get ("destination_ports" )
@@ -720,8 +719,11 @@ def clean(self):
720
719
if action == "remark" :
721
720
if not remark :
722
721
error_message ["remark" ] = [error_message_no_remark ]
723
- if source_prefix :
724
- error_message ["source_prefix" ] = [error_message_action_remark_source_prefix_set ]
722
+
723
+ # Check if action set to remark, but source set.
724
+ for source in sources :
725
+ error_message [source ] = [error_message_action_remark_source_set ]
726
+
725
727
if source_ports :
726
728
error_message ["source_ports" ] = ["Action is set to remark, Source Ports CANNOT be set." ]
727
729
if destination_prefix :
@@ -733,5 +735,10 @@ def clean(self):
733
735
elif remark :
734
736
error_message ["remark" ] = [error_message_remark_without_action_remark ]
735
737
738
+ # Check not more than one source is set.
739
+ elif sum (bool (cleaned_data .get (source )) for source in sources ) > 1 :
740
+ for source in sources :
741
+ error_message [source ] = [error_message_sources_more_than_one ]
742
+
736
743
if error_message :
737
744
raise ValidationError (error_message )
0 commit comments