diff --git a/netbox/extras/api/serializers.py b/netbox/extras/api/serializers.py index 4e1b47503..55e030a13 100644 --- a/netbox/extras/api/serializers.py +++ b/netbox/extras/api/serializers.py @@ -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', diff --git a/netbox/extras/filtersets.py b/netbox/extras/filtersets.py index d336394f9..3cbe8239b 100644 --- a/netbox/extras/filtersets.py +++ b/netbox/extras/filtersets.py @@ -58,6 +58,7 @@ class WebhookFilterSet(NetBoxModelFilterSet): return queryset return queryset.filter( Q(name__icontains=value) | + Q(description__icontains=value) | Q(payload_url__icontains=value) ) diff --git a/netbox/extras/forms/bulk_edit.py b/netbox/extras/forms/bulk_edit.py index 5da2a5dde..b44d29c9c 100644 --- a/netbox/extras/forms/bulk_edit.py +++ b/netbox/extras/forms/bulk_edit.py @@ -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, @@ -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): diff --git a/netbox/extras/forms/bulk_import.py b/netbox/extras/forms/bulk_import.py index 181b1f8d3..be0a0c63f 100644 --- a/netbox/extras/forms/bulk_import.py +++ b/netbox/extras/forms/bulk_import.py @@ -154,7 +154,7 @@ class WebhookImportForm(NetBoxModelImportForm): 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' ) diff --git a/netbox/extras/forms/model_forms.py b/netbox/extras/forms/model_forms.py index 9553a839a..659c7d9ef 100644 --- a/netbox/extras/forms/model_forms.py +++ b/netbox/extras/forms/model_forms.py @@ -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', diff --git a/netbox/extras/migrations/0102_webhook_description.py b/netbox/extras/migrations/0102_webhook_description.py new file mode 100644 index 000000000..cdf1eaa73 --- /dev/null +++ b/netbox/extras/migrations/0102_webhook_description.py @@ -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), + ), + ] diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index d0a2e4b61..367b835b1 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -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, diff --git a/netbox/extras/search.py b/netbox/extras/search.py index da4aa1c84..3394f37e8 100644 --- a/netbox/extras/search.py +++ b/netbox/extras/search.py @@ -9,3 +9,12 @@ class JournalEntryIndex(SearchIndex): ('comments', 5000), ) category = 'Journal' + + +@register_search +class WebhookEntryIndex(SearchIndex): + model = models.Webhook + fields = ( + ('name', 100), + ('description', 500), + ) diff --git a/netbox/extras/tables/tables.py b/netbox/extras/tables/tables.py index b78ab0c94..d44953632 100644 --- a/netbox/extras/tables/tables.py +++ b/netbox/extras/tables/tables.py @@ -283,11 +283,11 @@ class WebhookTable(NetBoxTable): 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', ) diff --git a/netbox/extras/tests/test_api.py b/netbox/extras/tests/test_api.py index 255457f21..025712e36 100644 --- a/netbox/extras/tests/test_api.py +++ b/netbox/extras/tests/test_api.py @@ -51,6 +51,7 @@ class WebhookTest(APIViewTestCases.APIViewTestCase): }, ] bulk_update_data = { + 'description': 'New description', 'ssl_verification': False, } diff --git a/netbox/extras/tests/test_views.py b/netbox/extras/tests/test_views.py index 3d4b3e9a9..aa0a21909 100644 --- a/netbox/extras/tests/test_views.py +++ b/netbox/extras/tests/test_views.py @@ -356,20 +356,21 @@ class WebhookTestCase(ViewTestCases.PrimaryObjectViewTestCase): '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 = { @@ -378,6 +379,7 @@ class WebhookTestCase(ViewTestCases.PrimaryObjectViewTestCase): 'type_update': True, 'type_delete': True, 'http_method': 'GET', + 'description': 'New description', } diff --git a/netbox/templates/extras/webhook.html b/netbox/templates/extras/webhook.html index 5137b0103..3338e3f30 100644 --- a/netbox/templates/extras/webhook.html +++ b/netbox/templates/extras/webhook.html @@ -16,6 +16,10 @@ {% trans "Name" %} {{ object.name }} + + {% trans "Description" %} + {{ object.description|placeholder }} + {% trans "Enabled" %} {% checkmark object.enabled %}