Просмотр исходного кода

fixed #2584 - validation for connecting front port to corresponding rear port

John Anderson 7 лет назад
Родитель
Сommit
9543b5e716
1 измененных файлов с 11 добавлено и 1 удалено
  1. 11 1
      netbox/dcim/models.py

+ 11 - 1
netbox/dcim/models.py

@@ -2530,9 +2530,19 @@ class Cable(ChangeLoggedModel):
 
         # A termination point cannot be connected to itself
         if self.termination_a == self.termination_b:
-            print("Validation failed: same interface")
             raise ValidationError("Cannot connect {} to itself".format(self.termination_a_type))
 
+        # A front port cannot be connected to its corresponding rear port
+        if (
+            type_a in ['frontport', 'rearport'] and
+            type_b in ['frontport', 'rearport'] and
+            (
+                getattr(self.termination_a, 'rear_port', None) == self.termination_b or
+                getattr(self.termination_b, 'rear_port', None) == self.termination_a
+            )
+        ):
+            raise ValidationError("A front port cannot be connected to it corresponding rear port")
+
         # Check for an existing Cable connected to either termination object
         if self.termination_a.cable not in (None, self):
             raise ValidationError("{} already has a cable attached (#{})".format(