Skip to content

Commit b3235c5

Browse files
committed
Closes netbox-community#14361: Add webhook description
1 parent d2fea4e commit b3235c5

File tree

11 files changed

+58
-17
lines changed

11 files changed

+58
-17
lines changed

docs/models/extras/webhook.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ See the [webhooks documentation](../../integrations/webhooks.md) for more inform
1010

1111
A unique human-friendly name.
1212

13+
### Description
14+
15+
A brief description of the webhook's purpose (optional).
16+
1317
### Content Types
1418

1519
The type(s) of object in NetBox that will trigger the webhook.

netbox/extras/api/serializers.py

Lines changed: 1 addition & 1 deletion
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/forms/bulk_edit.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm):
177177
queryset=Webhook.objects.all(),
178178
widget=forms.MultipleHiddenInput
179179
)
180+
description = forms.CharField(
181+
label=_('Description'),
182+
required=False
183+
)
180184
enabled = forms.NullBooleanField(
181185
label=_('Enabled'),
182186
required=False,
@@ -230,7 +234,7 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm):
230234
label=_('CA file path')
231235
)
232236

233-
nullable_fields = ('secret', 'conditions', 'ca_file_path')
237+
nullable_fields = ('description', 'secret', 'conditions', 'ca_file_path')
234238

235239

236240
class TagBulkEditForm(BulkEditForm):

netbox/extras/forms/bulk_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class WebhookImportForm(NetBoxModelImportForm):
152152
class Meta:
153153
model = Webhook
154154
fields = (
155-
'name', 'enabled', 'content_types', 'type_create', 'type_update', 'type_delete', 'type_job_start',
155+
'name', 'description', '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',
157157
'secret', 'ssl_verification', 'ca_file_path', 'tags'
158158
)

netbox/extras/forms/model_forms.py

Lines changed: 1 addition & 1 deletion
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',
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.7 on 2023-11-29 00:21
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

Lines changed: 5 additions & 0 deletions
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/tables/tables.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ class WebhookTable(NetBoxTable):
250250
verbose_name=_('Name'),
251251
linkify=True
252252
)
253+
description = columns.MarkdownColumn(
254+
verbose_name=_('Description')
255+
)
253256
content_types = columns.ContentTypesColumn(
254257
verbose_name=_('Content Types'),
255258
)
@@ -283,11 +286,11 @@ class Meta(NetBoxTable.Meta):
283286
fields = (
284287
'pk', 'id', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete',
285288
'type_job_start', 'type_job_end', 'http_method', 'payload_url', 'secret', 'ssl_validation', 'ca_file_path',
286-
'tags', 'created', 'last_updated',
289+
'tags', 'created', 'last_updated', 'description'
287290
)
288291
default_columns = (
289292
'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'type_job_start',
290-
'type_job_end', 'http_method', 'payload_url',
293+
'type_job_end', 'http_method', 'payload_url', 'description'
291294
)
292295

293296

netbox/extras/tests/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class WebhookTest(APIViewTestCases.APIViewTestCase):
5252
]
5353
bulk_update_data = {
5454
'ssl_verification': False,
55+
'description': 'New description'
5556
}
5657

5758
@classmethod

netbox/extras/tests/test_views.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,17 @@ def setUpTestData(cls):
338338

339339
site_ct = ContentType.objects.get_for_model(Site)
340340
webhooks = (
341-
Webhook(name='Webhook 1', payload_url='http://example.com/?1', type_create=True, http_method='POST'),
342-
Webhook(name='Webhook 2', payload_url='http://example.com/?2', type_create=True, http_method='POST'),
343-
Webhook(name='Webhook 3', payload_url='http://example.com/?3', type_create=True, http_method='POST'),
341+
Webhook(name='Webhook 1', description='Webhook 1 description', payload_url='http://example.com/?1', type_create=True, http_method='POST'),
342+
Webhook(name='Webhook 2', description='Webhook 2 description', payload_url='http://example.com/?2', type_create=True, http_method='POST'),
343+
Webhook(name='Webhook 3', description='Webhook 3 description', payload_url='http://example.com/?3', type_create=True, http_method='POST'),
344344
)
345345
for webhook in webhooks:
346346
webhook.save()
347347
webhook.content_types.add(site_ct)
348348

349349
cls.form_data = {
350350
'name': 'Webhook X',
351+
'description': 'A new webhook',
351352
'content_types': [site_ct.pk],
352353
'type_create': False,
353354
'type_update': True,
@@ -359,20 +360,21 @@ def setUpTestData(cls):
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,description,content_types,type_create,payload_url,http_method,http_content_type",
364+
"Webhook 4,Webhook 4 description,dcim.site,True,http://example.com/?4,GET,application/json",
365+
"Webhook 5,Webhook 5 description,dcim.site,True,http://example.com/?5,GET,application/json",
366+
"Webhook 6,Webhook 6 description,dcim.site,True,http://example.com/?6,GET,application/json",
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,Webhook 7 description",
372+
f"{webhooks[1].pk},Webhook 8,Webhook 8 description",
373+
f"{webhooks[2].pk},Webhook 9,Webhook 9 description",
373374
)
374375

375376
cls.bulk_edit_data = {
377+
'description': 'New description',
376378
'enabled': False,
377379
'type_create': False,
378380
'type_update': True,

netbox/templates/extras/webhook.html

Lines changed: 4 additions & 0 deletions
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|markdown|placeholder }}</td>
22+
</tr>
1923
<tr>
2024
<th scope="row">{% trans "Enabled" %}</th>
2125
<td>{% checkmark object.enabled %}</td>

0 commit comments

Comments
 (0)