Skip to content

Commit 7bfbe46

Browse files
committed
Closes #14361: Add a description field to Webhook
1 parent d2fea4e commit 7bfbe46

File tree

12 files changed

+59
-14
lines changed

12 files changed

+59
-14
lines changed

netbox/extras/api/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class WebhookSerializer(NetBoxModelSerializer):
7070
class Meta:
7171
model = Webhook
7272
fields = [
73-
'id', 'url', 'display', 'content_types', 'name', 'type_create', 'type_update', 'type_delete',
73+
'id', 'url', 'display', 'content_types', 'name', 'description', 'type_create', 'type_update', 'type_delete',
7474
'type_job_start', 'type_job_end', 'payload_url', 'enabled', 'http_method', 'http_content_type',
7575
'additional_headers', 'body_template', 'secret', 'conditions', 'ssl_verification', 'ca_file_path',
7676
'custom_fields', 'tags', 'created', 'last_updated',

netbox/extras/filtersets.py

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def search(self, queryset, name, value):
5858
return queryset
5959
return queryset.filter(
6060
Q(name__icontains=value) |
61+
Q(description__icontains=value) |
6162
Q(payload_url__icontains=value)
6263
)
6364

netbox/extras/forms/bulk_edit.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm):
177177
queryset=Webhook.objects.all(),
178178
widget=forms.MultipleHiddenInput
179179
)
180+
description = forms.CharField(
181+
label=_('Description'),
182+
max_length=200,
183+
required=False
184+
)
180185
enabled = forms.NullBooleanField(
181186
label=_('Enabled'),
182187
required=False,
@@ -230,7 +235,7 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm):
230235
label=_('CA file path')
231236
)
232237

233-
nullable_fields = ('secret', 'conditions', 'ca_file_path')
238+
nullable_fields = ('description', 'secret', 'conditions', 'ca_file_path')
234239

235240

236241
class TagBulkEditForm(BulkEditForm):

netbox/extras/forms/bulk_import.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class Meta:
154154
fields = (
155155
'name', 'enabled', 'content_types', 'type_create', 'type_update', 'type_delete', 'type_job_start',
156156
'type_job_end', 'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template',
157-
'secret', 'ssl_verification', 'ca_file_path', 'tags'
157+
'secret', 'ssl_verification', 'ca_file_path', 'description', 'tags'
158158
)
159159

160160

netbox/extras/forms/model_forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class WebhookForm(NetBoxModelForm):
217217
)
218218

219219
fieldsets = (
220-
(_('Webhook'), ('name', 'content_types', 'enabled', 'tags')),
220+
(_('Webhook'), ('name', 'description', 'content_types', 'enabled', 'tags')),
221221
(_('Events'), ('type_create', 'type_update', 'type_delete', 'type_job_start', 'type_job_end')),
222222
(_('HTTP Request'), (
223223
'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.7 on 2023-11-29 15:33
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('extras', '0101_move_configrevision'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='webhook',
15+
name='description',
16+
field=models.CharField(blank=True, max_length=200),
17+
),
18+
]

netbox/extras/models/models.py

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class Webhook(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedMo
5353
max_length=150,
5454
unique=True
5555
)
56+
description = models.CharField(
57+
verbose_name=_('description'),
58+
max_length=200,
59+
blank=True
60+
)
5661
type_create = models.BooleanField(
5762
verbose_name=_('on create'),
5863
default=False,

netbox/extras/search.py

+9
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ class JournalEntryIndex(SearchIndex):
99
('comments', 5000),
1010
)
1111
category = 'Journal'
12+
13+
14+
@register_search
15+
class WebhookEntryIndex(SearchIndex):
16+
model = models.Webhook
17+
fields = (
18+
('name', 100),
19+
('description', 500),
20+
)

netbox/extras/tables/tables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ class Meta(NetBoxTable.Meta):
283283
fields = (
284284
'pk', 'id', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete',
285285
'type_job_start', 'type_job_end', 'http_method', 'payload_url', 'secret', 'ssl_validation', 'ca_file_path',
286-
'tags', 'created', 'last_updated',
286+
'description', 'tags', 'created', 'last_updated',
287287
)
288288
default_columns = (
289289
'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'type_job_start',
290-
'type_job_end', 'http_method', 'payload_url',
290+
'type_job_end', 'http_method', 'payload_url', 'description',
291291
)
292292

293293

netbox/extras/tests/test_api.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class WebhookTest(APIViewTestCases.APIViewTestCase):
5151
},
5252
]
5353
bulk_update_data = {
54+
'description': 'New description',
5455
'ssl_verification': False,
5556
}
5657

netbox/extras/tests/test_views.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -356,20 +356,21 @@ def setUpTestData(cls):
356356
'http_method': 'GET',
357357
'http_content_type': 'application/foo',
358358
'conditions': None,
359+
'description': 'My webhook',
359360
}
360361

361362
cls.csv_data = (
362-
"name,content_types,type_create,payload_url,http_method,http_content_type",
363-
"Webhook 4,dcim.site,True,http://example.com/?4,GET,application/json",
364-
"Webhook 5,dcim.site,True,http://example.com/?5,GET,application/json",
365-
"Webhook 6,dcim.site,True,http://example.com/?6,GET,application/json",
363+
"name,content_types,type_create,payload_url,http_method,http_content_type,description",
364+
"Webhook 4,dcim.site,True,http://example.com/?4,GET,application/json,Foo",
365+
"Webhook 5,dcim.site,True,http://example.com/?5,GET,application/json,Bar",
366+
"Webhook 6,dcim.site,True,http://example.com/?6,GET,application/json,Baz",
366367
)
367368

368369
cls.csv_update_data = (
369-
"id,name",
370-
f"{webhooks[0].pk},Webhook 7",
371-
f"{webhooks[1].pk},Webhook 8",
372-
f"{webhooks[2].pk},Webhook 9",
370+
"id,name,description",
371+
f"{webhooks[0].pk},Webhook 7,Foo",
372+
f"{webhooks[1].pk},Webhook 8,Bar",
373+
f"{webhooks[2].pk},Webhook 9,Baz",
373374
)
374375

375376
cls.bulk_edit_data = {
@@ -378,6 +379,7 @@ def setUpTestData(cls):
378379
'type_update': True,
379380
'type_delete': True,
380381
'http_method': 'GET',
382+
'description': 'New description',
381383
}
382384

383385

netbox/templates/extras/webhook.html

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ <h5 class="card-header">
1616
<th scope="row">{% trans "Name" %}</th>
1717
<td>{{ object.name }}</td>
1818
</tr>
19+
<tr>
20+
<th scope="row">{% trans "Description" %}</th>
21+
<td>{{ object.description|placeholder }}</td>
22+
</tr>
1923
<tr>
2024
<th scope="row">{% trans "Enabled" %}</th>
2125
<td>{% checkmark object.enabled %}</td>

0 commit comments

Comments
 (0)