55
55
56
56
# Sets a standard error message for ACL rules with an action of remark, but no source is set.
57
57
error_message_action_remark_source_set = "Action is set to remark, Source CANNOT be set."
58
+ # Sets a standard error message for ACL rules with an action of remark, but no destination is set.
59
+ error_message_action_remark_destination_set = "Action is set to remark, Destination CANNOT be set."
58
60
59
61
# Sets a standard error message for ACL rules when more than one IP/Host sources are set.
60
62
error_message_sources_more_than_one = "Only one IP/Host related Source can be specified."
63
+ # Sets a standard error message for ACL rules when more than one IP/Host destinations are set.
64
+ error_message_destinations_more_than_one = "Only one IP/Host related Destination can be specified."
61
65
62
66
class AccessListForm (NetBoxModelForm ):
63
67
"""
@@ -719,9 +723,11 @@ def clean(self):
719
723
Validates form inputs before submitting:
720
724
- Check if action set to remark, but no remark set.
721
725
- Check if action set to remark, but source set.
726
+ - Check if action set to remark, but destination set.
722
727
- Check if action set to remark, but protocol set
723
728
- Check remark set, but action not set to remark.
724
729
- Check not more than one source is set.
730
+ - Check not more than one destination is set.
725
731
"""
726
732
super ().clean ()
727
733
cleaned_data = self .cleaned_data
@@ -731,8 +737,9 @@ def clean(self):
731
737
remark = cleaned_data .get ("remark" )
732
738
733
739
sources = ["source_prefix" , "source_iprange" , "source_ipaddress" , "source_aggregate" , "source_service" ]
740
+ destinations = ["destination_prefix" , "destination_iprange" , "destination_ipaddress" , "destination_aggregate" , "destination_service" ]
741
+
734
742
source_ports = cleaned_data .get ("source_ports" )
735
- destination_prefix = cleaned_data .get ("destination_prefix" )
736
743
destination_ports = cleaned_data .get ("destination_ports" )
737
744
protocol = cleaned_data .get ("protocol" )
738
745
@@ -743,11 +750,13 @@ def clean(self):
743
750
# Check if action set to remark, but source set.
744
751
for source in sources :
745
752
error_message [source ] = [error_message_action_remark_source_set ]
753
+
754
+ # Check if action set to remark, but destination set.
755
+ for destination in destinations :
756
+ error_message [destination ] = [error_message_action_remark_destination_set ]
746
757
747
758
if source_ports :
748
759
error_message ["source_ports" ] = ["Action is set to remark, Source Ports CANNOT be set." ]
749
- if destination_prefix :
750
- error_message ["destination_prefix" ] = ["Action is set to remark, Destination Prefix CANNOT be set." ]
751
760
if destination_ports :
752
761
error_message ["destination_ports" ] = ["Action is set to remark, Destination Ports CANNOT be set." ]
753
762
if protocol :
@@ -760,5 +769,10 @@ def clean(self):
760
769
for source in sources :
761
770
error_message [source ] = [error_message_sources_more_than_one ]
762
771
772
+ # Check not more than one destination is set.
773
+ elif sum (bool (cleaned_data .get (destination )) for destination in destinations ) > 1 :
774
+ for destination in destinations :
775
+ error_message [destination ] = [error_message_destinations_more_than_one ]
776
+
763
777
if error_message :
764
778
raise ValidationError (error_message )
0 commit comments