mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 12:12:53 -06:00
Clean up, update Webhook models
This commit is contained in:
parent
000fde25c6
commit
2f3c39295c
@ -195,13 +195,36 @@ WEBHOOK_CT_CHOICES = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Models which support registered webhooks
|
# Models which support registered webhooks
|
||||||
WEBHOOK_MODELS = (
|
WEBHOOK_MODELS = [
|
||||||
'provider', 'circuit', # Circuits
|
'circuits.circuit',
|
||||||
'site', 'rack', 'devicetype', 'device', 'virtualchassis', # DCIM
|
'circuits.provider',
|
||||||
'consoleport', 'consoleserverport', 'powerport', 'poweroutlet',
|
'dcim.cable',
|
||||||
'interface', 'devicebay', 'inventoryitem',
|
'dcim.consoleport',
|
||||||
'aggregate', 'prefix', 'ipaddress', 'vlan', 'vrf', 'service', # IPAM
|
'dcim.consoleserverport',
|
||||||
'secret', # Secrets
|
'dcim.device',
|
||||||
'tenant', # Tenancy
|
'dcim.devicebay',
|
||||||
'cluster', 'virtualmachine', # Virtualization
|
'dcim.devicetype',
|
||||||
)
|
'dcim.interface',
|
||||||
|
'dcim.inventoryitem',
|
||||||
|
'dcim.frontport',
|
||||||
|
'dcim.manufacturer',
|
||||||
|
'dcim.poweroutlet',
|
||||||
|
'dcim.powerpanel',
|
||||||
|
'dcim.powerport',
|
||||||
|
'dcim.powerfeed',
|
||||||
|
'dcim.rack',
|
||||||
|
'dcim.rearport',
|
||||||
|
'dcim.region',
|
||||||
|
'dcim.site',
|
||||||
|
'dcim.virtualchassis',
|
||||||
|
'ipam.aggregate',
|
||||||
|
'ipam.ipaddress',
|
||||||
|
'ipam.prefix',
|
||||||
|
'ipam.service',
|
||||||
|
'ipam.vlan',
|
||||||
|
'ipam.vrf',
|
||||||
|
'secrets.secret',
|
||||||
|
'tenancy.tenant',
|
||||||
|
'virtualization.cluster',
|
||||||
|
'virtualization.virtualmachine',
|
||||||
|
]
|
||||||
|
@ -29,7 +29,7 @@ class Migration(migrations.Migration):
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
# Update limit_choices_to for CustomFields and ExportTemplates
|
# Update limit_choices_to for CustomFields, ExportTemplates, and Webhooks
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='customfield',
|
model_name='customfield',
|
||||||
name='obj_type',
|
name='obj_type',
|
||||||
@ -40,4 +40,9 @@ class Migration(migrations.Migration):
|
|||||||
name='content_type',
|
name='content_type',
|
||||||
field=models.ForeignKey(limit_choices_to=extras.models.get_export_template_models, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'),
|
field=models.ForeignKey(limit_choices_to=extras.models.get_export_template_models, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'),
|
||||||
),
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='webhook',
|
||||||
|
name='obj_type',
|
||||||
|
field=models.ManyToManyField(limit_choices_to=extras.models.get_webhook_models, related_name='webhooks', to='contenttypes.ContentType'),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
@ -26,6 +26,10 @@ from .querysets import ConfigContextQuerySet
|
|||||||
# Webhooks
|
# Webhooks
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def get_webhook_models():
|
||||||
|
return model_names_to_filter_dict(WEBHOOK_MODELS)
|
||||||
|
|
||||||
|
|
||||||
class Webhook(models.Model):
|
class Webhook(models.Model):
|
||||||
"""
|
"""
|
||||||
A Webhook defines a request that will be sent to a remote application when an object is created, updated, and/or
|
A Webhook defines a request that will be sent to a remote application when an object is created, updated, and/or
|
||||||
@ -37,7 +41,7 @@ class Webhook(models.Model):
|
|||||||
to=ContentType,
|
to=ContentType,
|
||||||
related_name='webhooks',
|
related_name='webhooks',
|
||||||
verbose_name='Object types',
|
verbose_name='Object types',
|
||||||
limit_choices_to={'model__in': WEBHOOK_MODELS},
|
limit_choices_to=get_webhook_models,
|
||||||
help_text="The object(s) to which this Webhook applies."
|
help_text="The object(s) to which this Webhook applies."
|
||||||
)
|
)
|
||||||
name = models.CharField(
|
name = models.CharField(
|
||||||
|
@ -14,7 +14,7 @@ def enqueue_webhooks(instance, user, request_id, action):
|
|||||||
Find Webhook(s) assigned to this instance + action and enqueue them
|
Find Webhook(s) assigned to this instance + action and enqueue them
|
||||||
to be processed
|
to be processed
|
||||||
"""
|
"""
|
||||||
if not settings.WEBHOOKS_ENABLED or instance._meta.model_name not in WEBHOOK_MODELS:
|
if not settings.WEBHOOKS_ENABLED or instance._meta.label.lower() not in WEBHOOK_MODELS:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Retrieve any applicable Webhooks
|
# Retrieve any applicable Webhooks
|
||||||
|
Loading…
Reference in New Issue
Block a user