From a5c56b73f19bd9908dbfde5271a4e6e1b0be5d2b Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Tue, 1 Aug 2023 22:21:55 +0530 Subject: [PATCH] adds tags on webhook model #11936 --- netbox/extras/api/serializers.py | 4 ++-- netbox/extras/filtersets.py | 2 +- netbox/extras/forms/bulk_edit.py | 4 ---- netbox/extras/forms/bulk_import.py | 4 +--- netbox/extras/forms/filtersets.py | 5 +++-- netbox/extras/forms/model_forms.py | 4 +--- netbox/extras/graphql/types.py | 4 ++-- ....py => 0098_webhook_custom_field_data_webhook_tags.py} | 8 +++++++- netbox/extras/models/models.py | 2 +- netbox/extras/tables/tables.py | 5 ++++- netbox/templates/extras/webhook.html | 1 + 11 files changed, 23 insertions(+), 20 deletions(-) rename netbox/extras/migrations/{0098_webhook_custom_field_data.py => 0098_webhook_custom_field_data_webhook_tags.py} (61%) diff --git a/netbox/extras/api/serializers.py b/netbox/extras/api/serializers.py index 266a376cb9..dd684d3a5f 100644 --- a/netbox/extras/api/serializers.py +++ b/netbox/extras/api/serializers.py @@ -61,7 +61,7 @@ # Webhooks # -class WebhookSerializer(CustomFieldModelSerializer, ValidatedModelSerializer): +class WebhookSerializer(NetBoxModelSerializer): url = serializers.HyperlinkedIdentityField(view_name='extras-api:webhook-detail') content_types = ContentTypeField( queryset=ContentType.objects.filter(FeatureQuery('webhooks').get_query()), @@ -74,7 +74,7 @@ class Meta: 'id', 'url', 'display', 'content_types', 'name', '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', 'created', 'last_updated', + 'custom_fields', 'tags', 'created', 'last_updated', ] diff --git a/netbox/extras/filtersets.py b/netbox/extras/filtersets.py index 80fe2d2531..fec0672635 100644 --- a/netbox/extras/filtersets.py +++ b/netbox/extras/filtersets.py @@ -34,7 +34,7 @@ ) -class WebhookFilterSet(BaseFilterSet): +class WebhookFilterSet(NetBoxModelFilterSet): q = django_filters.CharFilter( method='search', label=_('Search'), diff --git a/netbox/extras/forms/bulk_edit.py b/netbox/extras/forms/bulk_edit.py index 02e7b462ef..821ce7eb24 100644 --- a/netbox/extras/forms/bulk_edit.py +++ b/netbox/extras/forms/bulk_edit.py @@ -226,10 +226,6 @@ class WebhookBulkEditForm(NetBoxModelBulkEditForm): label=_('CA file path') ) - add_tags = None - - remove_tags = None - nullable_fields = ('secret', 'conditions', 'ca_file_path') diff --git a/netbox/extras/forms/bulk_import.py b/netbox/extras/forms/bulk_import.py index 419f06c0e8..466baa2415 100644 --- a/netbox/extras/forms/bulk_import.py +++ b/netbox/extras/forms/bulk_import.py @@ -148,14 +148,12 @@ class WebhookImportForm(NetBoxModelImportForm): help_text=_("One or more assigned object types") ) - tags = None - class Meta: model = Webhook 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' + 'secret', 'ssl_verification', 'ca_file_path', 'tags' ) diff --git a/netbox/extras/forms/filtersets.py b/netbox/extras/forms/filtersets.py index cc292f60f6..88cbf9e4d8 100644 --- a/netbox/extras/forms/filtersets.py +++ b/netbox/extras/forms/filtersets.py @@ -219,11 +219,12 @@ class SavedFilterFilterForm(SavedFiltersMixin, FilterForm): ) -class WebhookFilterForm(CustomFieldsMixin, SavedFiltersMixin, FilterForm): +class WebhookFilterForm(NetBoxModelFilterSetForm): model = Webhook + tag = TagFilterField(model) fieldsets = ( - (None, ('q', 'filter_id')), + (None, ('q', 'filter_id', 'tag')), (_('Attributes'), ('content_type_id', 'http_method', 'enabled')), (_('Events'), ('type_create', 'type_update', 'type_delete', 'type_job_start', 'type_job_end')), ) diff --git a/netbox/extras/forms/model_forms.py b/netbox/extras/forms/model_forms.py index 9f13bed66b..0dc384867a 100644 --- a/netbox/extras/forms/model_forms.py +++ b/netbox/extras/forms/model_forms.py @@ -221,10 +221,8 @@ class WebhookForm(NetBoxModelForm): limit_choices_to=FeatureQuery('webhooks') ) - tags = None - fieldsets = ( - (_('Webhook'), ('name', 'content_types', 'enabled')), + (_('Webhook'), ('name', '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', diff --git a/netbox/extras/graphql/types.py b/netbox/extras/graphql/types.py index b3c6a4abb5..068da02f2b 100644 --- a/netbox/extras/graphql/types.py +++ b/netbox/extras/graphql/types.py @@ -1,6 +1,6 @@ from extras import filtersets, models from extras.graphql.mixins import CustomFieldsMixin, TagsMixin -from netbox.graphql.types import BaseObjectType, ObjectType +from netbox.graphql.types import BaseObjectType, ObjectType, OrganizationalObjectType __all__ = ( 'ConfigContextType', @@ -106,7 +106,7 @@ class Meta: filterset_class = filtersets.TagFilterSet -class WebhookType(CustomFieldsMixin, ObjectType): +class WebhookType(OrganizationalObjectType): class Meta: model = models.Webhook diff --git a/netbox/extras/migrations/0098_webhook_custom_field_data.py b/netbox/extras/migrations/0098_webhook_custom_field_data_webhook_tags.py similarity index 61% rename from netbox/extras/migrations/0098_webhook_custom_field_data.py rename to netbox/extras/migrations/0098_webhook_custom_field_data_webhook_tags.py index d9f2da0b8d..3fd2943881 100644 --- a/netbox/extras/migrations/0098_webhook_custom_field_data.py +++ b/netbox/extras/migrations/0098_webhook_custom_field_data_webhook_tags.py @@ -1,6 +1,7 @@ -# Generated by Django 4.1.10 on 2023-08-01 15:29 +# Generated by Django 4.1.10 on 2023-08-01 16:32 from django.db import migrations, models +import taggit.managers import utilities.json @@ -16,4 +17,9 @@ class Migration(migrations.Migration): name='custom_field_data', field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder), ), + migrations.AddField( + model_name='webhook', + name='tags', + field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'), + ), ] diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index 144032f1f8..47aa557dbf 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -39,7 +39,7 @@ ) -class Webhook(CustomFieldsMixin, ExportTemplatesMixin, ChangeLoggedModel): +class Webhook(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedModel): """ A Webhook defines a request that will be sent to a remote application when an object is created, updated, and/or delete in NetBox. The request will contain a representation of the object, which the remote application can act on. diff --git a/netbox/extras/tables/tables.py b/netbox/extras/tables/tables.py index baff0efbb9..9e14a2d274 100644 --- a/netbox/extras/tables/tables.py +++ b/netbox/extras/tables/tables.py @@ -297,13 +297,16 @@ class WebhookTable(NetBoxTable): ssl_validation = columns.BooleanColumn( verbose_name=_('SSL Validation') ) + tags = columns.TagColumn( + url_name='extras:webhook_list' + ) class Meta(NetBoxTable.Meta): model = Webhook 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', - 'created', 'last_updated', + 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'type_job_start', diff --git a/netbox/templates/extras/webhook.html b/netbox/templates/extras/webhook.html index 7bfd4cc0c3..5137b0103a 100644 --- a/netbox/templates/extras/webhook.html +++ b/netbox/templates/extras/webhook.html @@ -148,6 +148,7 @@
{% include 'inc/panels/custom_fields.html' %} + {% include 'inc/panels/tags.html' %} {% plugin_right_page object %}