Skip to content

Commit

Permalink
Fixes netbox-community#10423: Enforce object type validation when cre…
Browse files Browse the repository at this point in the history
…ating journal entries
  • Loading branch information
jeremystretch committed Oct 4, 2022
1 parent 53f5f46 commit fec8d1b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/version-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* [#9497](https://github.com/netbox-community/netbox/issues/9497) - Adjust non-racked device filter on site and location detailed view
* [#10408](https://github.com/netbox-community/netbox/issues/10408) - Fix validation when attempting to add redundant contact assignments
* [#10423](https://github.com/netbox-community/netbox/issues/10423) - Enforce object type validation when creating journal entries
* [#10435](https://github.com/netbox-community/netbox/issues/10435) - Fix exception when filtering VLANs by virtual machine with no cluster assigned
* [#10439](https://github.com/netbox-community/netbox/issues/10439) - Fix form widget styling for DeviceType airflow field
* [#10445](https://github.com/netbox-community/netbox/issues/10445) - Avoid rounding virtual machine memory values
Expand Down
8 changes: 8 additions & 0 deletions netbox/extras/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ def __str__(self):
def get_absolute_url(self):
return reverse('extras:journalentry', args=[self.pk])

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

# Prevent the creation of journal entries on unsupported models
permitted_types = ContentType.objects.filter(FeatureQuery('journaling').get_query())
if self.assigned_object_type not in permitted_types:
raise ValidationError(f"Journaling is not supported for this object type ({self.assigned_object_type}).")

def get_kind_color(self):
return JournalEntryKindChoices.colors.get(self.kind)

Expand Down
3 changes: 1 addition & 2 deletions netbox/netbox/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class NetBoxFeatureSet(
CustomLinksMixin,
CustomValidationMixin,
ExportTemplatesMixin,
JournalingMixin,
TagsMixin,
WebhooksMixin
):
Expand Down Expand Up @@ -51,7 +50,7 @@ class Meta:
abstract = True


class NetBoxModel(CloningMixin, NetBoxFeatureSet, models.Model):
class NetBoxModel(CloningMixin, JournalingMixin, NetBoxFeatureSet, models.Model):
"""
Primary models represent real objects within the infrastructure being modeled.
"""
Expand Down

0 comments on commit fec8d1b

Please sign in to comment.