From 4b5181d640ebe1b2b6d9521eabe5a36296dc81f9 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 8 Nov 2018 10:40:17 -0500 Subject: [PATCH] Fixes #2566: Prevent both ends of a cable from connecting to the same termination point --- CHANGELOG.md | 1 + netbox/dcim/models.py | 5 +++++ netbox/project-static/js/livesearch.js | 1 - 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ddf38c0c..8eaff04c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ NetBox now supports modeling physical cables for console, power, and interface c ## Bug Fixes (from v2.5-beta1) * [#2563](https://github.com/digitalocean/netbox/issues/2563) - Enable export templates for cables +* [#2566](https://github.com/digitalocean/netbox/issues/2566) - Prevent both ends of a cable from connecting to the same termination point * [#2567](https://github.com/digitalocean/netbox/issues/2567) - Introduced proxy models to represent console/power/interface connections ## API Changes diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index e9eb80276..22a830123 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -2516,6 +2516,11 @@ class Cable(ChangeLoggedModel): self.termination_a_type, self.termination_b_type )) + # 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)) + # 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( diff --git a/netbox/project-static/js/livesearch.js b/netbox/project-static/js/livesearch.js index e00aefbaf..6df1f23ef 100644 --- a/netbox/project-static/js/livesearch.js +++ b/netbox/project-static/js/livesearch.js @@ -42,7 +42,6 @@ $(document).ready(function() { event.preventDefault(); search_field.val(ui.item.label); select_fields.val(''); - select_fields.attr('disabled', 'disabled'); real_field.empty(); real_field.append($("").attr('value', ui.item.value).text(ui.item.label)); real_field.change();