Skip to content

Commit

Permalink
Closes #14361: Add a description field to Webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Nov 29, 2023
1 parent d2fea4e commit 7bfbe46
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion netbox/extras/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class WebhookSerializer(NetBoxModelSerializer):
class Meta:
model = Webhook
fields = [
'id', 'url', 'display', 'content_types', 'name', 'type_create', 'type_update', 'type_delete',
'id', 'url', 'display', 'content_types', 'name', 'description', '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',
'custom_fields', 'tags', 'created', 'last_updated',
Expand Down
1 change: 1 addition & 0 deletions netbox/extras/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def search(self, queryset, name, value):
return queryset
return queryset.filter(
Q(name__icontains=value) |
Q(description__icontains=value) |
Q(payload_url__icontains=value)
)

Expand Down
7 changes: 6 additions & 1 deletion netbox/extras/forms/bulk_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm):
queryset=Webhook.objects.all(),
widget=forms.MultipleHiddenInput
)
description = forms.CharField(
label=_('Description'),
max_length=200,
required=False
)
enabled = forms.NullBooleanField(
label=_('Enabled'),
required=False,
Expand Down Expand Up @@ -230,7 +235,7 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm):
label=_('CA file path')
)

nullable_fields = ('secret', 'conditions', 'ca_file_path')
nullable_fields = ('description', 'secret', 'conditions', 'ca_file_path')


class TagBulkEditForm(BulkEditForm):
Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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', 'tags'
'secret', 'ssl_verification', 'ca_file_path', 'description', 'tags'
)


Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class WebhookForm(NetBoxModelForm):
)

fieldsets = (
(_('Webhook'), ('name', 'content_types', 'enabled', 'tags')),
(_('Webhook'), ('name', 'description', '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
18 changes: 18 additions & 0 deletions netbox/extras/migrations/0102_webhook_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2023-11-29 15:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('extras', '0101_move_configrevision'),
]

operations = [
migrations.AddField(
model_name='webhook',
name='description',
field=models.CharField(blank=True, max_length=200),
),
]
5 changes: 5 additions & 0 deletions netbox/extras/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class Webhook(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedMo
max_length=150,
unique=True
)
description = models.CharField(
verbose_name=_('description'),
max_length=200,
blank=True
)
type_create = models.BooleanField(
verbose_name=_('on create'),
default=False,
Expand Down
9 changes: 9 additions & 0 deletions netbox/extras/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ class JournalEntryIndex(SearchIndex):
('comments', 5000),
)
category = 'Journal'


@register_search
class WebhookEntryIndex(SearchIndex):
model = models.Webhook
fields = (
('name', 100),
('description', 500),
)
4 changes: 2 additions & 2 deletions netbox/extras/tables/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ class Meta(NetBoxTable.Meta):
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',
'tags', 'created', 'last_updated',
'description', 'tags', 'created', 'last_updated',
)
default_columns = (
'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'type_job_start',
'type_job_end', 'http_method', 'payload_url',
'type_job_end', 'http_method', 'payload_url', 'description',
)


Expand Down
1 change: 1 addition & 0 deletions netbox/extras/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class WebhookTest(APIViewTestCases.APIViewTestCase):
},
]
bulk_update_data = {
'description': 'New description',
'ssl_verification': False,
}

Expand Down
18 changes: 10 additions & 8 deletions netbox/extras/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,21 @@ def setUpTestData(cls):
'http_method': 'GET',
'http_content_type': 'application/foo',
'conditions': None,
'description': 'My webhook',
}

cls.csv_data = (
"name,content_types,type_create,payload_url,http_method,http_content_type",
"Webhook 4,dcim.site,True,http://example.com/?4,GET,application/json",
"Webhook 5,dcim.site,True,http://example.com/?5,GET,application/json",
"Webhook 6,dcim.site,True,http://example.com/?6,GET,application/json",
"name,content_types,type_create,payload_url,http_method,http_content_type,description",
"Webhook 4,dcim.site,True,http://example.com/?4,GET,application/json,Foo",
"Webhook 5,dcim.site,True,http://example.com/?5,GET,application/json,Bar",
"Webhook 6,dcim.site,True,http://example.com/?6,GET,application/json,Baz",
)

cls.csv_update_data = (
"id,name",
f"{webhooks[0].pk},Webhook 7",
f"{webhooks[1].pk},Webhook 8",
f"{webhooks[2].pk},Webhook 9",
"id,name,description",
f"{webhooks[0].pk},Webhook 7,Foo",
f"{webhooks[1].pk},Webhook 8,Bar",
f"{webhooks[2].pk},Webhook 9,Baz",
)

cls.bulk_edit_data = {
Expand All @@ -378,6 +379,7 @@ def setUpTestData(cls):
'type_update': True,
'type_delete': True,
'http_method': 'GET',
'description': 'New description',
}


Expand Down
4 changes: 4 additions & 0 deletions netbox/templates/extras/webhook.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ <h5 class="card-header">
<th scope="row">{% trans "Name" %}</th>
<td>{{ object.name }}</td>
</tr>
<tr>
<th scope="row">{% trans "Description" %}</th>
<td>{{ object.description|placeholder }}</td>
</tr>
<tr>
<th scope="row">{% trans "Enabled" %}</th>
<td>{% checkmark object.enabled %}</td>
Expand Down

0 comments on commit 7bfbe46

Please sign in to comment.