diff --git a/netbox/extras/api/serializers.py b/netbox/extras/api/serializers.py index 82b3e1933..ffd0df9ab 100644 --- a/netbox/extras/api/serializers.py +++ b/netbox/extras/api/serializers.py @@ -107,9 +107,9 @@ class WebhookSerializer(NetBoxModelSerializer): class Meta: model = Webhook fields = [ - 'id', 'url', 'display', 'name', 'payload_url', 'http_method', 'http_content_type', 'additional_headers', - 'body_template', 'secret', 'ssl_verification', 'ca_file_path', 'custom_fields', 'tags', 'created', - 'last_updated', + 'id', 'url', 'display', 'name', 'description', 'payload_url', 'http_method', 'http_content_type', + 'additional_headers', 'body_template', 'secret', 'ssl_verification', 'ca_file_path', 'custom_fields', + 'tags', 'created', 'last_updated', ] diff --git a/netbox/extras/filtersets.py b/netbox/extras/filtersets.py index e3eeda20d..5d36a34c7 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 dade76bad..9479fef99 100644 --- a/netbox/extras/forms/bulk_edit.py +++ b/netbox/extras/forms/bulk_edit.py @@ -178,6 +178,11 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm): queryset=Webhook.objects.all(), widget=forms.MultipleHiddenInput ) + description = forms.CharField( + label=_('Description'), + max_length=200, + required=False + ) http_method = forms.ChoiceField( choices=add_blank_choice(WebhookHttpMethodChoices), required=False, @@ -242,7 +247,7 @@ class EventRuleBulkEditForm(NetBoxModelBulkEditForm): widget=BulkEditNullBooleanSelect() ) - nullable_fields = ('conditions',) + nullable_fields = ('description', 'conditions',) class TagBulkEditForm(BulkEditForm): diff --git a/netbox/extras/forms/bulk_import.py b/netbox/extras/forms/bulk_import.py index 82930e8ad..e08a6528d 100644 --- a/netbox/extras/forms/bulk_import.py +++ b/netbox/extras/forms/bulk_import.py @@ -150,7 +150,7 @@ class WebhookImportForm(NetBoxModelImportForm): model = Webhook fields = ( 'name', '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 0c717246f..9403165e9 100644 --- a/netbox/extras/forms/model_forms.py +++ b/netbox/extras/forms/model_forms.py @@ -215,7 +215,7 @@ class BookmarkForm(BootstrapMixin, forms.ModelForm): class WebhookForm(NetBoxModelForm): fieldsets = ( - (_('Webhook'), ('name', 'tags',)), + (_('Webhook'), ('name', 'description', 'tags',)), (_('HTTP Request'), ( 'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret', )), diff --git a/netbox/extras/migrations/0101_eventrule.py b/netbox/extras/migrations/0101_eventrule.py index 64e03dda0..92ae0e52b 100644 --- a/netbox/extras/migrations/0101_eventrule.py +++ b/netbox/extras/migrations/0101_eventrule.py @@ -124,4 +124,9 @@ class Migration(migrations.Migration): name='tags', field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'), ), + 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 e5f71dba3..f996b50b5 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -182,6 +182,11 @@ class Webhook(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedMo max_length=150, unique=True ) + description = models.CharField( + verbose_name=_('description'), + max_length=200, + blank=True + ) payload_url = models.CharField( max_length=500, verbose_name=_('URL'), 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 ece23093b..e02365531 100644 --- a/netbox/extras/tables/tables.py +++ b/netbox/extras/tables/tables.py @@ -262,10 +262,10 @@ class WebhookTable(NetBoxTable): model = Webhook fields = ( 'pk', 'id', 'name', 'http_method', 'payload_url', 'http_content_type', 'secret', 'ssl_verification', - 'ca_file_path', 'tags', 'created', 'last_updated', + 'ca_file_path', 'description', 'tags', 'created', 'last_updated', ) default_columns = ( - 'pk', 'name', 'http_method', 'payload_url', + 'pk', 'name', 'http_method', 'payload_url', 'description', ) diff --git a/netbox/extras/tests/test_api.py b/netbox/extras/tests/test_api.py index b35fb8d66..93be2d2c4 100644 --- a/netbox/extras/tests/test_api.py +++ b/netbox/extras/tests/test_api.py @@ -46,6 +46,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 602a9d4de..dcb351f75 100644 --- a/netbox/extras/tests/test_views.py +++ b/netbox/extras/tests/test_views.py @@ -347,20 +347,21 @@ class WebhookTestCase(ViewTestCases.PrimaryObjectViewTestCase): 'payload_url': 'http://example.com/?x', 'http_method': 'GET', 'http_content_type': 'application/foo', + 'description': 'My webhook', } cls.csv_data = ( - "name,payload_url,http_method,http_content_type", - "Webhook 4,http://example.com/?4,GET,application/json", - "Webhook 5,http://example.com/?5,GET,application/json", - "Webhook 6,http://example.com/?6,GET,application/json", + "name,payload_url,http_method,http_content_type,description", + "Webhook 4,http://example.com/?4,GET,application/json,Foo", + "Webhook 5,http://example.com/?5,GET,application/json,Bar", + "Webhook 6,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 = { @@ -403,7 +404,8 @@ class EventRulesTestCase(ViewTestCases.PrimaryObjectViewTestCase): 'action_type': 'webhook', 'action_object_type': webhook_ct.pk, 'action_object_id': webhooks[0].pk, - 'action_choice': webhooks[0] + 'action_choice': webhooks[0], + 'description': 'New description', } cls.csv_data = ( diff --git a/netbox/templates/extras/webhook.html b/netbox/templates/extras/webhook.html index c4b41faa1..0f390d3e4 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 }} +