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:
|
class Meta:
|
||||||
model = Webhook
|
model = Webhook
|
||||||
fields = [
|
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',
|
'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',
|
'additional_headers', 'body_template', 'secret', 'conditions', 'ssl_verification', 'ca_file_path',
|
||||||
'custom_fields', 'tags', 'created', 'last_updated',
|
'custom_fields', 'tags', 'created', 'last_updated',
|
||||||
|
@ -58,6 +58,7 @@ class WebhookFilterSet(NetBoxModelFilterSet):
|
|||||||
return queryset
|
return queryset
|
||||||
return queryset.filter(
|
return queryset.filter(
|
||||||
Q(name__icontains=value) |
|
Q(name__icontains=value) |
|
||||||
|
Q(description__icontains=value) |
|
||||||
Q(payload_url__icontains=value)
|
Q(payload_url__icontains=value)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -177,6 +177,11 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
queryset=Webhook.objects.all(),
|
queryset=Webhook.objects.all(),
|
||||||
widget=forms.MultipleHiddenInput
|
widget=forms.MultipleHiddenInput
|
||||||
)
|
)
|
||||||
|
description = forms.CharField(
|
||||||
|
label=_('Description'),
|
||||||
|
max_length=200,
|
||||||
|
required=False
|
||||||
|
)
|
||||||
enabled = forms.NullBooleanField(
|
enabled = forms.NullBooleanField(
|
||||||
label=_('Enabled'),
|
label=_('Enabled'),
|
||||||
required=False,
|
required=False,
|
||||||
@ -230,7 +235,7 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
label=_('CA file path')
|
label=_('CA file path')
|
||||||
)
|
)
|
||||||
|
|
||||||
nullable_fields = ('secret', 'conditions', 'ca_file_path')
|
nullable_fields = ('description', 'secret', 'conditions', 'ca_file_path')
|
||||||
|
|
||||||
|
|
||||||
class TagBulkEditForm(BulkEditForm):
|
class TagBulkEditForm(BulkEditForm):
|
||||||
|
@ -154,7 +154,7 @@ class WebhookImportForm(NetBoxModelImportForm):
|
|||||||
fields = (
|
fields = (
|
||||||
'name', 'enabled', 'content_types', 'type_create', 'type_update', 'type_delete', 'type_job_start',
|
'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',
|
'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 = (
|
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')),
|
(_('Events'), ('type_create', 'type_update', 'type_delete', 'type_job_start', 'type_job_end')),
|
||||||
(_('HTTP Request'), (
|
(_('HTTP Request'), (
|
||||||
'payload_url', 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret',
|
'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,
|
max_length=150,
|
||||||
unique=True
|
unique=True
|
||||||
)
|
)
|
||||||
|
description = models.CharField(
|
||||||
|
verbose_name=_('description'),
|
||||||
|
max_length=200,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
type_create = models.BooleanField(
|
type_create = models.BooleanField(
|
||||||
verbose_name=_('on create'),
|
verbose_name=_('on create'),
|
||||||
default=False,
|
default=False,
|
||||||
|
@ -9,3 +9,12 @@ class JournalEntryIndex(SearchIndex):
|
|||||||
('comments', 5000),
|
('comments', 5000),
|
||||||
)
|
)
|
||||||
category = 'Journal'
|
category = 'Journal'
|
||||||
|
|
||||||
|
|
||||||
|
@register_search
|
||||||
|
class WebhookEntryIndex(SearchIndex):
|
||||||
|
model = models.Webhook
|
||||||
|
fields = (
|
||||||
|
('name', 100),
|
||||||
|
('description', 500),
|
||||||
|
)
|
||||||
|
@ -283,11 +283,11 @@ class WebhookTable(NetBoxTable):
|
|||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete',
|
'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',
|
'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 = (
|
default_columns = (
|
||||||
'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'type_job_start',
|
'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 = {
|
bulk_update_data = {
|
||||||
|
'description': 'New description',
|
||||||
'ssl_verification': False,
|
'ssl_verification': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,20 +356,21 @@ class WebhookTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
'http_method': 'GET',
|
'http_method': 'GET',
|
||||||
'http_content_type': 'application/foo',
|
'http_content_type': 'application/foo',
|
||||||
'conditions': None,
|
'conditions': None,
|
||||||
|
'description': 'My webhook',
|
||||||
}
|
}
|
||||||
|
|
||||||
cls.csv_data = (
|
cls.csv_data = (
|
||||||
"name,content_types,type_create,payload_url,http_method,http_content_type",
|
"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",
|
"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",
|
"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",
|
"Webhook 6,dcim.site,True,http://example.com/?6,GET,application/json,Baz",
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.csv_update_data = (
|
cls.csv_update_data = (
|
||||||
"id,name",
|
"id,name,description",
|
||||||
f"{webhooks[0].pk},Webhook 7",
|
f"{webhooks[0].pk},Webhook 7,Foo",
|
||||||
f"{webhooks[1].pk},Webhook 8",
|
f"{webhooks[1].pk},Webhook 8,Bar",
|
||||||
f"{webhooks[2].pk},Webhook 9",
|
f"{webhooks[2].pk},Webhook 9,Baz",
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.bulk_edit_data = {
|
cls.bulk_edit_data = {
|
||||||
@ -378,6 +379,7 @@ class WebhookTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
'type_update': True,
|
'type_update': True,
|
||||||
'type_delete': True,
|
'type_delete': True,
|
||||||
'http_method': 'GET',
|
'http_method': 'GET',
|
||||||
|
'description': 'New description',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
<th scope="row">{% trans "Name" %}</th>
|
<th scope="row">{% trans "Name" %}</th>
|
||||||
<td>{{ object.name }}</td>
|
<td>{{ object.name }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans "Description" %}</th>
|
||||||
|
<td>{{ object.description|placeholder }}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Enabled" %}</th>
|
<th scope="row">{% trans "Enabled" %}</th>
|
||||||
<td>{% checkmark object.enabled %}</td>
|
<td>{% checkmark object.enabled %}</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user