Skip to content

Commit b812a50

Browse files
Closes #14361: Add a description field to Webhook (#14380)
1 parent a38a382 commit b812a50

File tree

12 files changed

+49
-17
lines changed

12 files changed

+49
-17
lines changed

netbox/extras/api/serializers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ class WebhookSerializer(NetBoxModelSerializer):
107107
class Meta:
108108
model = Webhook
109109
fields = [
110-
'id', 'url', 'display', 'name', 'payload_url', 'http_method', 'http_content_type', 'additional_headers',
111-
'body_template', 'secret', 'ssl_verification', 'ca_file_path', 'custom_fields', 'tags', 'created',
112-
'last_updated',
110+
'id', 'url', 'display', 'name', 'description', 'payload_url', 'http_method', 'http_content_type',
111+
'additional_headers', 'body_template', 'secret', 'ssl_verification', 'ca_file_path', 'custom_fields',
112+
'tags', 'created', 'last_updated',
113113
]
114114

115115

netbox/extras/filtersets.py

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm):
178178
queryset=Webhook.objects.all(),
179179
widget=forms.MultipleHiddenInput
180180
)
181+
description = forms.CharField(
182+
label=_('Description'),
183+
max_length=200,
184+
required=False
185+
)
181186
http_method = forms.ChoiceField(
182187
choices=add_blank_choice(WebhookHttpMethodChoices),
183188
required=False,
@@ -242,7 +247,7 @@ class EventRuleBulkEditForm(NetBoxModelBulkEditForm):
242247
widget=BulkEditNullBooleanSelect()
243248
)
244249

245-
nullable_fields = ('conditions',)
250+
nullable_fields = ('description', 'conditions',)
246251

247252

248253
class TagBulkEditForm(BulkEditForm):

netbox/extras/forms/bulk_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class Meta:
150150
model = Webhook
151151
fields = (
152152
'name', 'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template',
153-
'secret', 'ssl_verification', 'ca_file_path', 'tags'
153+
'secret', 'ssl_verification', 'ca_file_path', 'description', 'tags'
154154
)
155155

156156

netbox/extras/forms/model_forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class Meta:
215215
class WebhookForm(NetBoxModelForm):
216216

217217
fieldsets = (
218-
(_('Webhook'), ('name', 'tags',)),
218+
(_('Webhook'), ('name', 'description', 'tags',)),
219219
(_('HTTP Request'), (
220220
'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret',
221221
)),

netbox/extras/migrations/0101_eventrule.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,9 @@ class Migration(migrations.Migration):
124124
name='tags',
125125
field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'),
126126
),
127+
migrations.AddField(
128+
model_name='webhook',
129+
name='description',
130+
field=models.CharField(blank=True, max_length=200),
131+
),
127132
]

netbox/extras/models/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ class Webhook(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedMo
182182
max_length=150,
183183
unique=True
184184
)
185+
description = models.CharField(
186+
verbose_name=_('description'),
187+
max_length=200,
188+
blank=True
189+
)
185190
payload_url = models.CharField(
186191
max_length=500,
187192
verbose_name=_('URL'),

netbox/extras/search.py

Lines changed: 9 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ class Meta(NetBoxTable.Meta):
262262
model = Webhook
263263
fields = (
264264
'pk', 'id', 'name', 'http_method', 'payload_url', 'http_content_type', 'secret', 'ssl_verification',
265-
'ca_file_path', 'tags', 'created', 'last_updated',
265+
'ca_file_path', 'description', 'tags', 'created', 'last_updated',
266266
)
267267
default_columns = (
268-
'pk', 'name', 'http_method', 'payload_url',
268+
'pk', 'name', 'http_method', 'payload_url', 'description',
269269
)
270270

271271

netbox/extras/tests/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class WebhookTest(APIViewTestCases.APIViewTestCase):
4646
},
4747
]
4848
bulk_update_data = {
49+
'description': 'New description',
4950
'ssl_verification': False,
5051
}
5152

netbox/extras/tests/test_views.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,20 +347,21 @@ def setUpTestData(cls):
347347
'payload_url': 'http://example.com/?x',
348348
'http_method': 'GET',
349349
'http_content_type': 'application/foo',
350+
'description': 'My webhook',
350351
}
351352

352353
cls.csv_data = (
353-
"name,payload_url,http_method,http_content_type",
354-
"Webhook 4,http://example.com/?4,GET,application/json",
355-
"Webhook 5,http://example.com/?5,GET,application/json",
356-
"Webhook 6,http://example.com/?6,GET,application/json",
354+
"name,payload_url,http_method,http_content_type,description",
355+
"Webhook 4,http://example.com/?4,GET,application/json,Foo",
356+
"Webhook 5,http://example.com/?5,GET,application/json,Bar",
357+
"Webhook 6,http://example.com/?6,GET,application/json,Baz",
357358
)
358359

359360
cls.csv_update_data = (
360-
"id,name",
361-
f"{webhooks[0].pk},Webhook 7",
362-
f"{webhooks[1].pk},Webhook 8",
363-
f"{webhooks[2].pk},Webhook 9",
361+
"id,name,description",
362+
f"{webhooks[0].pk},Webhook 7,Foo",
363+
f"{webhooks[1].pk},Webhook 8,Bar",
364+
f"{webhooks[2].pk},Webhook 9,Baz",
364365
)
365366

366367
cls.bulk_edit_data = {
@@ -403,7 +404,8 @@ def setUpTestData(cls):
403404
'action_type': 'webhook',
404405
'action_object_type': webhook_ct.pk,
405406
'action_object_id': webhooks[0].pk,
406-
'action_choice': webhooks[0]
407+
'action_choice': webhooks[0],
408+
'description': 'New description',
407409
}
408410

409411
cls.csv_data = (

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|placeholder }}</td>
22+
</tr>
1923
</table>
2024
</div>
2125
</div>

0 commit comments

Comments
 (0)