From ba00d57d3743ef55ada967fa83a7747909973d84 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 2 Dec 2020 14:49:07 -0500 Subject: [PATCH] Closes #4711: Rename Webhook.obj_type to content_types --- docs/release-notes/version-2.10.md | 4 ++++ netbox/extras/admin.py | 10 +++++----- .../migrations/0053_rename_webhook_obj_type.py | 18 ++++++++++++++++++ netbox/extras/models/models.py | 3 +-- netbox/extras/tests/test_webhooks.py | 2 +- netbox/extras/webhooks.py | 4 ++-- 6 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 netbox/extras/migrations/0053_rename_webhook_obj_type.py diff --git a/docs/release-notes/version-2.10.md b/docs/release-notes/version-2.10.md index 4ff839b6e..0c1d8e0cc 100644 --- a/docs/release-notes/version-2.10.md +++ b/docs/release-notes/version-2.10.md @@ -15,6 +15,10 @@ * [#5376](https://github.com/netbox-community/netbox/issues/5376) - Correct invalid custom field filter logic values * [#5395](https://github.com/netbox-community/netbox/issues/5395) - Fix cable tracing for rear ports with no corresponding front port +### Other Changes + +* [#4711](https://github.com/netbox-community/netbox/issues/4711) - Renamed Webhook `obj_type` to `content_types` + --- ## v2.10-beta1 (2020-11-17) diff --git a/netbox/extras/admin.py b/netbox/extras/admin.py index e83165aaf..a4786610d 100644 --- a/netbox/extras/admin.py +++ b/netbox/extras/admin.py @@ -29,8 +29,8 @@ class WebhookForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - if 'obj_type' in self.fields: - order_content_types(self.fields['obj_type']) + if 'content_types' in self.fields: + order_content_types(self.fields['content_types']) @admin.register(Webhook) @@ -40,12 +40,12 @@ class WebhookAdmin(admin.ModelAdmin): 'ssl_verification', ] list_filter = [ - 'enabled', 'type_create', 'type_update', 'type_delete', 'obj_type', + 'enabled', 'type_create', 'type_update', 'type_delete', 'content_types', ] form = WebhookForm fieldsets = ( (None, { - 'fields': ('name', 'obj_type', 'enabled') + 'fields': ('name', 'content_types', 'enabled') }), ('Events', { 'fields': ('type_create', 'type_update', 'type_delete') @@ -62,7 +62,7 @@ class WebhookAdmin(admin.ModelAdmin): ) def models(self, obj): - return ', '.join([ct.name for ct in obj.obj_type.all()]) + return ', '.join([ct.name for ct in obj.content_types.all()]) # diff --git a/netbox/extras/migrations/0053_rename_webhook_obj_type.py b/netbox/extras/migrations/0053_rename_webhook_obj_type.py new file mode 100644 index 000000000..05bbebad8 --- /dev/null +++ b/netbox/extras/migrations/0053_rename_webhook_obj_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2020-12-02 19:41 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('extras', '0052_customfield_cleanup'), + ] + + operations = [ + migrations.RenameField( + model_name='webhook', + old_name='obj_type', + new_name='content_types', + ), + ] diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index 8fe43fbca..8934d9732 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -31,8 +31,7 @@ class Webhook(models.Model): delete in NetBox. The request will contain a representation of the object, which the remote application can act on. Each Webhook can be limited to firing only on certain actions or certain object types. """ - # TODO: Rename obj_type to content_types (see #4711) - obj_type = models.ManyToManyField( + content_types = models.ManyToManyField( to=ContentType, related_name='webhooks', verbose_name='Object types', diff --git a/netbox/extras/tests/test_webhooks.py b/netbox/extras/tests/test_webhooks.py index 8f741bbc2..d8f30e26e 100644 --- a/netbox/extras/tests/test_webhooks.py +++ b/netbox/extras/tests/test_webhooks.py @@ -39,7 +39,7 @@ class WebhookTest(APITestCase): Webhook(name='Site Delete Webhook', type_delete=True, payload_url=DUMMY_URL, secret=DUMMY_SECRET), )) for webhook in webhooks: - webhook.obj_type.set([site_ct]) + webhook.content_types.set([site_ct]) def test_enqueue_webhook_create(self): # Create an object via the REST API diff --git a/netbox/extras/webhooks.py b/netbox/extras/webhooks.py index 9166c463a..f062e5752 100644 --- a/netbox/extras/webhooks.py +++ b/netbox/extras/webhooks.py @@ -35,13 +35,13 @@ def enqueue_webhooks(instance, user, request_id, action): return # Retrieve any applicable Webhooks - obj_type = ContentType.objects.get_for_model(instance) + content_type = ContentType.objects.get_for_model(instance) action_flag = { ObjectChangeActionChoices.ACTION_CREATE: 'type_create', ObjectChangeActionChoices.ACTION_UPDATE: 'type_update', ObjectChangeActionChoices.ACTION_DELETE: 'type_delete', }[action] - webhooks = Webhook.objects.filter(obj_type=obj_type, enabled=True, **{action_flag: True}) + webhooks = Webhook.objects.filter(content_types=content_type, enabled=True, **{action_flag: True}) if webhooks.exists(): # Get the Model's API serializer class and serialize the object