From 42c71984f93047d7434704a5af02bfaa14cdd3dd Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 11 Aug 2021 21:15:45 -0400 Subject: [PATCH 1/5] Fixes #6896: Fix validation of IP address assigned as device/VM primary via NAT relation --- docs/release-notes/version-2.11.md | 1 + netbox/ipam/models/ip.py | 21 +++++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 705472ac5..cd15c8459 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -11,6 +11,7 @@ * [#6740](https://github.com/netbox-community/netbox/issues/6740) - Add import button to VM interfaces list * [#6892](https://github.com/netbox-community/netbox/issues/6892) - Fix validation of unit ranges when creating a rack reservation +* [#6896](https://github.com/netbox-community/netbox/issues/6896) - Fix validation of IP address assigned as device/VM primary via NAT relation * [#6902](https://github.com/netbox-community/netbox/issues/6902) - Populate device field when cloning device components * [#6908](https://github.com/netbox-community/netbox/issues/6908) - Allow assignment of scope to VLAN groups upon import * [#6909](https://github.com/netbox-community/netbox/issues/6909) - Remove extraneous `site` column from VLAN group import form diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index cd5b89cfe..b428e4be7 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -649,18 +649,15 @@ class IPAddress(PrimaryModel): # Check for primary IP assignment that doesn't match the assigned device/VM if self.pk: - device = Device.objects.filter(Q(primary_ip4=self) | Q(primary_ip6=self)).first() - if device: - if getattr(self.assigned_object, 'device', None) != device: - raise ValidationError({ - 'interface': f"IP address is primary for device {device} but not assigned to it!" - }) - vm = VirtualMachine.objects.filter(Q(primary_ip4=self) | Q(primary_ip6=self)).first() - if vm: - if getattr(self.assigned_object, 'virtual_machine', None) != vm: - raise ValidationError({ - 'vminterface': f"IP address is primary for virtual machine {vm} but not assigned to it!" - }) + for cls, attr in ((Device, 'device'), (VirtualMachine, 'virtual_machine')): + parent = cls.objects.filter(Q(primary_ip4=self) | Q(primary_ip6=self)).first() + if parent and getattr(self.assigned_object, attr) != parent: + # Check for a NAT relationship + if not self.nat_inside or getattr(self.nat_inside.assigned_object, attr) != parent: + raise ValidationError({ + 'interface': f"IP address is primary for {cls._meta.model_name} {parent} but " + f"not assigned to it!" + }) # Validate IP status selection if self.status == IPAddressStatusChoices.STATUS_SLAAC and self.family != 6: From 3105e9545a4735e77692b76d6f1caf058d72049a Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 12 Aug 2021 10:12:42 -0400 Subject: [PATCH 2/5] Fixes #6918: Fix return URL persistence when adding multiple objects sequentially --- docs/release-notes/version-2.11.md | 1 + netbox/ipam/forms.py | 6 +++--- netbox/netbox/views/generic.py | 17 +++++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index cd15c8459..722657587 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -16,6 +16,7 @@ * [#6908](https://github.com/netbox-community/netbox/issues/6908) - Allow assignment of scope to VLAN groups upon import * [#6909](https://github.com/netbox-community/netbox/issues/6909) - Remove extraneous `site` column from VLAN group import form * [#6910](https://github.com/netbox-community/netbox/issues/6910) - Fix exception on invalid CSV import column name +* [#6918](https://github.com/netbox-community/netbox/issues/6918) - Fix return URL persistence when adding multiple objects sequentially * [#6935](https://github.com/netbox-community/netbox/issues/6935) - Remove extraneous columns from inventory item and device bay tables * [#6936](https://github.com/netbox-community/netbox/issues/6936) - Add missing `parent` column to inventory item import form diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index d130c5895..c19131ca6 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -12,8 +12,8 @@ from tenancy.models import Tenant from utilities.forms import ( add_blank_choice, BootstrapMixin, BulkEditNullBooleanSelect, ContentTypeChoiceField, CSVChoiceField, CSVContentTypeField, CSVModelChoiceField, DatePicker, DynamicModelChoiceField, DynamicModelMultipleChoiceField, - ExpandableIPAddressField, NumericArrayField, ReturnURLForm, SlugField, StaticSelect2, StaticSelect2Multiple, - TagFilterField, BOOLEAN_WITH_BLANK_CHOICES, + ExpandableIPAddressField, NumericArrayField, SlugField, StaticSelect2, StaticSelect2Multiple, TagFilterField, + BOOLEAN_WITH_BLANK_CHOICES, ) from virtualization.models import Cluster, ClusterGroup, VirtualMachine, VMInterface from .choices import * @@ -682,7 +682,7 @@ class PrefixFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm) # IP addresses # -class IPAddressForm(BootstrapMixin, TenancyForm, ReturnURLForm, CustomFieldModelForm): +class IPAddressForm(BootstrapMixin, TenancyForm, CustomFieldModelForm): device = DynamicModelChoiceField( queryset=Device.objects.all(), required=False, diff --git a/netbox/netbox/views/generic.py b/netbox/netbox/views/generic.py index d26b56464..ae2840a42 100644 --- a/netbox/netbox/views/generic.py +++ b/netbox/netbox/views/generic.py @@ -306,19 +306,20 @@ class ObjectEditView(GetReturnURLMixin, ObjectPermissionRequiredMixin, View): messages.success(request, mark_safe(msg)) if '_addanother' in request.POST: + redirect_url = request.path + return_url = request.GET.get('return_url') + if return_url is not None and is_safe_url(url=return_url, allowed_hosts=request.get_host()): + redirect_url = f'{redirect_url}?return_url={return_url}' # If the object has clone_fields, pre-populate a new instance of the form if hasattr(obj, 'clone_fields'): - url = '{}?{}'.format(request.path, prepare_cloned_fields(obj)) - return redirect(url) + redirect_url += f"{'&' if return_url else '?'}{prepare_cloned_fields(obj)}" - return redirect(request.get_full_path()) + return redirect(redirect_url) - return_url = form.cleaned_data.get('return_url') - if return_url is not None and is_safe_url(url=return_url, allowed_hosts=request.get_host()): - return redirect(return_url) - else: - return redirect(self.get_return_url(request, obj)) + return_url = self.get_return_url(request, obj) + + return redirect(return_url) except PermissionsViolation: msg = "Object save failed due to object-level permissions violation" From b2faf8044dd3fcb138b5aa052d5e595b24e878d0 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 12 Aug 2021 11:22:57 -0400 Subject: [PATCH 3/5] Release v2.11.11 --- docs/release-notes/version-2.11.md | 2 +- netbox/netbox/settings.py | 2 +- requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 722657587..40df841c0 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -1,6 +1,6 @@ # NetBox v2.11 -## v2.11.11 (FUTURE) +## v2.11.11 (2021-08-12) ### Enhancements diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index d44d87b23..f9cab85be 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -16,7 +16,7 @@ from django.core.validators import URLValidator # Environment setup # -VERSION = '2.11.11-dev' +VERSION = '2.11.11' # Hostname HOSTNAME = platform.node() diff --git a/requirements.txt b/requirements.txt index d35cba435..65ce1de50 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django==3.2.5 +Django==3.2.6 django-cacheops==6.0 django-cors-headers==3.7.0 django-debug-toolbar==3.2.1 From badd92a50e6c8b59b589157c4f8f58e48281bde1 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 12 Aug 2021 11:28:55 -0400 Subject: [PATCH 4/5] Update GitHub issue templates --- .github/ISSUE_TEMPLATE/bug_report.yaml | 2 +- .github/ISSUE_TEMPLATE/feature_request.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index ef31324fe..b0c021af2 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -17,7 +17,7 @@ body: What version of NetBox are you currently running? (If you don't have access to the most recent NetBox release, consider testing on our [demo instance](https://demo.netbox.dev/) before opening a bug report to see if your issue has already been addressed.) - placeholder: v2.11.10 + placeholder: v2.11.11 validations: required: true - type: dropdown diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index 319538cda..f13d45c3f 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -14,7 +14,7 @@ body: attributes: label: NetBox version description: What version of NetBox are you currently running? - placeholder: v2.11.10 + placeholder: v2.11.11 validations: required: true - type: dropdown From 1b12185a39641e2ae9fb021a779e190d77e8ac9b Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 12 Aug 2021 11:47:59 -0400 Subject: [PATCH 5/5] PRVB --- netbox/netbox/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index f9cab85be..1f3cf8049 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -16,7 +16,7 @@ from django.core.validators import URLValidator # Environment setup # -VERSION = '2.11.11' +VERSION = '2.11.12-dev' # Hostname HOSTNAME = platform.node()