Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #14361: Add a description field to Webhook model #14380

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions netbox/extras/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]


Expand Down
1 change: 1 addition & 0 deletions netbox/extras/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def search(self, queryset, name, value):
return queryset
return queryset.filter(
Q(name__icontains=value) |
Q(description__icontains=value) |
Q(payload_url__icontains=value)
)

Expand Down
7 changes: 6 additions & 1 deletion netbox/extras/forms/bulk_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -242,7 +247,7 @@ class EventRuleBulkEditForm(NetBoxModelBulkEditForm):
widget=BulkEditNullBooleanSelect()
)

nullable_fields = ('conditions',)
nullable_fields = ('description', 'conditions',)


class TagBulkEditForm(BulkEditForm):
Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Meta:
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'
)


Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class Meta:
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',
)),
Expand Down
5 changes: 5 additions & 0 deletions netbox/extras/migrations/0101_eventrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
]
5 changes: 5 additions & 0 deletions netbox/extras/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
9 changes: 9 additions & 0 deletions netbox/extras/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ class JournalEntryIndex(SearchIndex):
('comments', 5000),
)
category = 'Journal'


@register_search
class WebhookEntryIndex(SearchIndex):
model = models.Webhook
fields = (
('name', 100),
('description', 500),
)
4 changes: 2 additions & 2 deletions netbox/extras/tables/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ class Meta(NetBoxTable.Meta):
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',
)


Expand Down
1 change: 1 addition & 0 deletions netbox/extras/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class WebhookTest(APIViewTestCases.APIViewTestCase):
},
]
bulk_update_data = {
'description': 'New description',
'ssl_verification': False,
}

Expand Down
20 changes: 11 additions & 9 deletions netbox/extras/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,20 +347,21 @@ def setUpTestData(cls):
'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 = {
Expand Down Expand Up @@ -403,7 +404,8 @@ def setUpTestData(cls):
'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 = (
Expand Down
4 changes: 4 additions & 0 deletions netbox/templates/extras/webhook.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ <h5 class="card-header">
<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>
Expand Down