1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #14361: Add a description field to Webhook (#14380)

This commit is contained in:
Jeremy Stretch
2023-11-30 17:02:45 -05:00
committed by GitHub
parent a38a38218b
commit b812a50ca2
12 changed files with 49 additions and 17 deletions

View File

@ -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',
]

View File

@ -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)
)

View File

@ -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):

View File

@ -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'
)

View File

@ -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',
)),

View File

@ -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),
),
]

View File

@ -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'),

View File

@ -9,3 +9,12 @@ class JournalEntryIndex(SearchIndex):
('comments', 5000),
)
category = 'Journal'
@register_search
class WebhookEntryIndex(SearchIndex):
model = models.Webhook
fields = (
('name', 100),
('description', 500),
)

View File

@ -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',
)

View File

@ -46,6 +46,7 @@ class WebhookTest(APIViewTestCases.APIViewTestCase):
},
]
bulk_update_data = {
'description': 'New description',
'ssl_verification': False,
}

View File

@ -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 = (

View File

@ -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>
</table>
</div>
</div>