mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Closes #4711: Rename Webhook.obj_type to content_types
This commit is contained in:
parent
f5133c6737
commit
ba00d57d37
@ -15,6 +15,10 @@
|
|||||||
* [#5376](https://github.com/netbox-community/netbox/issues/5376) - Correct invalid custom field filter logic values
|
* [#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
|
* [#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)
|
## v2.10-beta1 (2020-11-17)
|
||||||
|
@ -29,8 +29,8 @@ class WebhookForm(forms.ModelForm):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
if 'obj_type' in self.fields:
|
if 'content_types' in self.fields:
|
||||||
order_content_types(self.fields['obj_type'])
|
order_content_types(self.fields['content_types'])
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Webhook)
|
@admin.register(Webhook)
|
||||||
@ -40,12 +40,12 @@ class WebhookAdmin(admin.ModelAdmin):
|
|||||||
'ssl_verification',
|
'ssl_verification',
|
||||||
]
|
]
|
||||||
list_filter = [
|
list_filter = [
|
||||||
'enabled', 'type_create', 'type_update', 'type_delete', 'obj_type',
|
'enabled', 'type_create', 'type_update', 'type_delete', 'content_types',
|
||||||
]
|
]
|
||||||
form = WebhookForm
|
form = WebhookForm
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, {
|
(None, {
|
||||||
'fields': ('name', 'obj_type', 'enabled')
|
'fields': ('name', 'content_types', 'enabled')
|
||||||
}),
|
}),
|
||||||
('Events', {
|
('Events', {
|
||||||
'fields': ('type_create', 'type_update', 'type_delete')
|
'fields': ('type_create', 'type_update', 'type_delete')
|
||||||
@ -62,7 +62,7 @@ class WebhookAdmin(admin.ModelAdmin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def models(self, obj):
|
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()])
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
18
netbox/extras/migrations/0053_rename_webhook_obj_type.py
Normal file
18
netbox/extras/migrations/0053_rename_webhook_obj_type.py
Normal file
@ -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',
|
||||||
|
),
|
||||||
|
]
|
@ -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.
|
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.
|
Each Webhook can be limited to firing only on certain actions or certain object types.
|
||||||
"""
|
"""
|
||||||
# TODO: Rename obj_type to content_types (see #4711)
|
content_types = models.ManyToManyField(
|
||||||
obj_type = models.ManyToManyField(
|
|
||||||
to=ContentType,
|
to=ContentType,
|
||||||
related_name='webhooks',
|
related_name='webhooks',
|
||||||
verbose_name='Object types',
|
verbose_name='Object types',
|
||||||
|
@ -39,7 +39,7 @@ class WebhookTest(APITestCase):
|
|||||||
Webhook(name='Site Delete Webhook', type_delete=True, payload_url=DUMMY_URL, secret=DUMMY_SECRET),
|
Webhook(name='Site Delete Webhook', type_delete=True, payload_url=DUMMY_URL, secret=DUMMY_SECRET),
|
||||||
))
|
))
|
||||||
for webhook in webhooks:
|
for webhook in webhooks:
|
||||||
webhook.obj_type.set([site_ct])
|
webhook.content_types.set([site_ct])
|
||||||
|
|
||||||
def test_enqueue_webhook_create(self):
|
def test_enqueue_webhook_create(self):
|
||||||
# Create an object via the REST API
|
# Create an object via the REST API
|
||||||
|
@ -35,13 +35,13 @@ def enqueue_webhooks(instance, user, request_id, action):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Retrieve any applicable Webhooks
|
# Retrieve any applicable Webhooks
|
||||||
obj_type = ContentType.objects.get_for_model(instance)
|
content_type = ContentType.objects.get_for_model(instance)
|
||||||
action_flag = {
|
action_flag = {
|
||||||
ObjectChangeActionChoices.ACTION_CREATE: 'type_create',
|
ObjectChangeActionChoices.ACTION_CREATE: 'type_create',
|
||||||
ObjectChangeActionChoices.ACTION_UPDATE: 'type_update',
|
ObjectChangeActionChoices.ACTION_UPDATE: 'type_update',
|
||||||
ObjectChangeActionChoices.ACTION_DELETE: 'type_delete',
|
ObjectChangeActionChoices.ACTION_DELETE: 'type_delete',
|
||||||
}[action]
|
}[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():
|
if webhooks.exists():
|
||||||
# Get the Model's API serializer class and serialize the object
|
# Get the Model's API serializer class and serialize the object
|
||||||
|
Loading…
Reference in New Issue
Block a user