mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Closes #14361: Add a description field to Webhook
This commit is contained in:
parent
d2fea4edc4
commit
7bfbe4674d
@ -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',
|
||||
|
@ -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)
|
||||
)
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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'
|
||||
)
|
||||
|
||||
|
||||
|
@ -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',
|
||||
|
18
netbox/extras/migrations/0102_webhook_description.py
Normal file
18
netbox/extras/migrations/0102_webhook_description.py
Normal file
@ -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),
|
||||
),
|
||||
]
|
@ -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,
|
||||
|
@ -9,3 +9,12 @@ class JournalEntryIndex(SearchIndex):
|
||||
('comments', 5000),
|
||||
)
|
||||
category = 'Journal'
|
||||
|
||||
|
||||
@register_search
|
||||
class WebhookEntryIndex(SearchIndex):
|
||||
model = models.Webhook
|
||||
fields = (
|
||||
('name', 100),
|
||||
('description', 500),
|
||||
)
|
||||
|
@ -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',
|
||||
)
|
||||
|
||||
|
||||
|
@ -51,6 +51,7 @@ class WebhookTest(APIViewTestCases.APIViewTestCase):
|
||||
},
|
||||
]
|
||||
bulk_update_data = {
|
||||
'description': 'New description',
|
||||
'ssl_verification': False,
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,6 +16,10 @@
|
||||
<th scope="row">{% trans "Name" %}</th>
|
||||
<td>{{ object.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Description" %}</th>
|
||||
<td>{{ object.description|placeholder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Enabled" %}</th>
|
||||
<td>{% checkmark object.enabled %}</td>
|
||||
|
Loading…
Reference in New Issue
Block a user