Skip to content

Adds custom field on webhook model #13336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions netbox/extras/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# Webhooks
#

class WebhookSerializer(ValidatedModelSerializer):
class WebhookSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='extras-api:webhook-detail')
content_types = ContentTypeField(
queryset=ContentType.objects.filter(FeatureQuery('webhooks').get_query()),
Expand All @@ -74,7 +74,7 @@ class Meta:
'id', 'url', 'display', 'content_types', 'name', 'type_create', 'type_update', 'type_delete',
'type_job_start', 'type_job_end', 'payload_url', 'enabled', 'http_method', 'http_content_type',
'additional_headers', 'body_template', 'secret', 'conditions', 'ssl_verification', 'ca_file_path',
'created', 'last_updated',
'custom_fields', 'tags', 'created', 'last_updated',
]


Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
)


class WebhookFilterSet(BaseFilterSet):
class WebhookFilterSet(NetBoxModelFilterSet):
q = django_filters.CharFilter(
method='search',
label=_('Search'),
Expand Down
5 changes: 4 additions & 1 deletion netbox/extras/forms/bulk_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from extras.choices import *
from extras.models import *
from netbox.forms import NetBoxModelBulkEditForm
from utilities.forms import BulkEditForm, add_blank_choice
from utilities.forms.fields import ColorField, DynamicModelChoiceField
from utilities.forms.widgets import BulkEditNullBooleanSelect
Expand Down Expand Up @@ -165,7 +166,9 @@ class SavedFilterBulkEditForm(BulkEditForm):
nullable_fields = ('description',)


class WebhookBulkEditForm(BulkEditForm):
class WebhookBulkEditForm(NetBoxModelBulkEditForm):
model = Webhook

pk = forms.ModelMultipleChoiceField(
queryset=Webhook.objects.all(),
widget=forms.MultipleHiddenInput
Expand Down
4 changes: 2 additions & 2 deletions netbox/extras/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Meta:
)


class WebhookImportForm(CSVModelForm):
class WebhookImportForm(NetBoxModelImportForm):
content_types = CSVMultipleContentTypeField(
label=_('Content types'),
queryset=ContentType.objects.all(),
Expand All @@ -153,7 +153,7 @@ class Meta:
fields = (
'name', 'enabled', 'content_types', 'type_create', 'type_update', 'type_delete', 'type_job_start',
'type_job_end', 'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template',
'secret', 'ssl_verification', 'ca_file_path'
'secret', 'ssl_verification', 'ca_file_path', 'tags'
)


Expand Down
9 changes: 6 additions & 3 deletions netbox/extras/forms/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from utilities.forms.widgets import APISelectMultiple, DateTimePicker
from virtualization.models import Cluster, ClusterGroup, ClusterType
from .mixins import SavedFiltersMixin
from .mixins import *

__all__ = (
'ConfigContextFilterForm',
Expand Down Expand Up @@ -219,9 +219,12 @@ class SavedFilterFilterForm(SavedFiltersMixin, FilterForm):
)


class WebhookFilterForm(SavedFiltersMixin, FilterForm):
class WebhookFilterForm(NetBoxModelFilterSetForm):
model = Webhook
tag = TagFilterField(model)

fieldsets = (
(None, ('q', 'filter_id')),
(None, ('q', 'filter_id', 'tag')),
(_('Attributes'), ('content_type_id', 'http_method', 'enabled')),
(_('Events'), ('type_create', 'type_update', 'type_delete', 'type_job_start', 'type_job_end')),
)
Expand Down
4 changes: 2 additions & 2 deletions netbox/extras/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ class Meta:
fields = ('object_type', 'object_id')


class WebhookForm(BootstrapMixin, forms.ModelForm):
class WebhookForm(NetBoxModelForm):
content_types = ContentTypeMultipleChoiceField(
label=_('Content types'),
queryset=ContentType.objects.all(),
limit_choices_to=FeatureQuery('webhooks')
)

fieldsets = (
(_('Webhook'), ('name', 'content_types', 'enabled')),
(_('Webhook'), ('name', 'content_types', 'enabled', 'tags')),
(_('Events'), ('type_create', 'type_update', 'type_delete', 'type_job_start', 'type_job_end')),
(_('HTTP Request'), (
'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret',
Expand Down
4 changes: 2 additions & 2 deletions netbox/extras/graphql/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from extras import filtersets, models
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
from netbox.graphql.types import BaseObjectType, ObjectType
from netbox.graphql.types import BaseObjectType, ObjectType, OrganizationalObjectType

__all__ = (
'ConfigContextType',
Expand Down Expand Up @@ -106,7 +106,7 @@ class Meta:
filterset_class = filtersets.TagFilterSet


class WebhookType(ObjectType):
class WebhookType(OrganizationalObjectType):

class Meta:
model = models.Webhook
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.1.10 on 2023-08-01 16:32

from django.db import migrations, models
import taggit.managers
import utilities.json


class Migration(migrations.Migration):

dependencies = [
('extras', '0097_customfield_remove_choices'),
]

operations = [
migrations.AddField(
model_name='webhook',
name='custom_field_data',
field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
),
migrations.AddField(
model_name='webhook',
name='tags',
field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'),
),
]
2 changes: 1 addition & 1 deletion netbox/extras/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
)


class Webhook(ExportTemplatesMixin, ChangeLoggedModel):
class Webhook(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedModel):
"""
A Webhook defines a request that will be sent to a remote application when an object is created, updated, and/or
delete in NetBox. The request will contain a representation of the object, which the remote application can act on.
Expand Down
5 changes: 4 additions & 1 deletion netbox/extras/tables/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,16 @@ class WebhookTable(NetBoxTable):
ssl_validation = columns.BooleanColumn(
verbose_name=_('SSL Validation')
)
tags = columns.TagColumn(
url_name='extras:webhook_list'
)

class Meta(NetBoxTable.Meta):
model = Webhook
fields = (
'pk', 'id', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete',
'type_job_start', 'type_job_end', 'http_method', 'payload_url', 'secret', 'ssl_validation', 'ca_file_path',
'created', 'last_updated',
'tags', 'created', 'last_updated',
)
default_columns = (
'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'type_job_start',
Expand Down
2 changes: 2 additions & 0 deletions netbox/templates/extras/webhook.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ <h5 class="card-header">
{% endif %}
</div>
</div>
{% include 'inc/panels/custom_fields.html' %}
{% include 'inc/panels/tags.html' %}
{% plugin_right_page object %}
</div>
</div>
Expand Down