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