mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #3588: Enforce object-form JSON for local context data on devices and VMs
This commit is contained in:
@ -10,6 +10,7 @@
|
|||||||
* [#3574](https://github.com/netbox-community/netbox/issues/3574) - Change `device` to `parent` in interface editing VLAN filtering logic
|
* [#3574](https://github.com/netbox-community/netbox/issues/3574) - Change `device` to `parent` in interface editing VLAN filtering logic
|
||||||
* [#3575](https://github.com/netbox-community/netbox/issues/3575) - Restore label for comments field when bulk editing circuits
|
* [#3575](https://github.com/netbox-community/netbox/issues/3575) - Restore label for comments field when bulk editing circuits
|
||||||
* [#3582](https://github.com/netbox-community/netbox/issues/3582) - Enforce view permissions on global search results
|
* [#3582](https://github.com/netbox-community/netbox/issues/3582) - Enforce view permissions on global search results
|
||||||
|
* [#3588](https://github.com/netbox-community/netbox/issues/3588) - Enforce object-form JSON for local context data on devices and VMs
|
||||||
|
|
||||||
## Enhancements
|
## Enhancements
|
||||||
|
|
||||||
|
@ -1609,6 +1609,8 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
|||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
|
super().clean()
|
||||||
|
|
||||||
# Validate site/rack combination
|
# Validate site/rack combination
|
||||||
if self.rack and self.site != self.rack.site:
|
if self.rack and self.site != self.rack.site:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
|
@ -805,7 +805,10 @@ class ConfigContext(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class ConfigContextModel(models.Model):
|
class ConfigContextModel(models.Model):
|
||||||
|
"""
|
||||||
|
A model which includes local configuration context data. This local data will override any inherited data from
|
||||||
|
ConfigContexts.
|
||||||
|
"""
|
||||||
local_context_data = JSONField(
|
local_context_data = JSONField(
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
@ -830,6 +833,16 @@ class ConfigContextModel(models.Model):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
# Verify that JSON data is provided as an object
|
||||||
|
if self.local_context_data and type(self.local_context_data) is not dict:
|
||||||
|
raise ValidationError(
|
||||||
|
{'local_context_data': 'JSON data must be in object form. Example: {"foo": 123}'}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Custom scripts
|
# Custom scripts
|
||||||
|
@ -255,6 +255,8 @@ class VirtualMachine(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
|||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
|
super().clean()
|
||||||
|
|
||||||
# Validate primary IP addresses
|
# Validate primary IP addresses
|
||||||
interfaces = self.interfaces.all()
|
interfaces = self.interfaces.all()
|
||||||
for field in ['primary_ip4', 'primary_ip6']:
|
for field in ['primary_ip4', 'primary_ip6']:
|
||||||
|
Reference in New Issue
Block a user