Skip to content

Commit

Permalink
Fixes #11934: Prevent reassignment of an IP address designated as pri…
Browse files Browse the repository at this point in the history
…mary for its parent object
  • Loading branch information
jeremystretch committed May 25, 2023
1 parent 24a51dd commit b64b19a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/release-notes/version-3.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bug Fixes

* [#11934](https://github.com/netbox-community/netbox/issues/11934) - Prevent reassignment of an IP address designated as primary for its parent object
* [#12694](https://github.com/netbox-community/netbox/issues/12694) - Strip leading & trailing whitespace from custom link URL & text

---
Expand Down
13 changes: 12 additions & 1 deletion netbox/ipam/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ def __init__(self, *args, **kwargs):
):
self.initial['primary_for_parent'] = True

# Disable object assignment fields if the IP address is designated as primary
if self.initial.get('primary_for_parent'):
self.fields['interface'].disabled = True
self.fields['vminterface'].disabled = True
self.fields['fhrpgroup'].disabled = True

def clean(self):
super().clean()

Expand All @@ -340,7 +346,12 @@ def clean(self):
selected_objects[1]: "An IP address can only be assigned to a single object."
})
elif selected_objects:
self.instance.assigned_object = self.cleaned_data[selected_objects[0]]
assigned_object = self.cleaned_data[selected_objects[0]]
if self.cleaned_data['primary_for_parent'] and assigned_object != self.instance.assigned_object:
raise ValidationError(
"Cannot reassign IP address while it is designated as the primary IP for the parent object"
)
self.instance.assigned_object = assigned_object
else:
self.instance.assigned_object = None

Expand Down

0 comments on commit b64b19a

Please sign in to comment.