#3892: Convert WEBHOOK_MODELS to a Q object

This commit is contained in:
Jeremy Stretch
2020-01-15 16:18:47 -05:00
parent 985e57bd7d
commit f506db78f6
6 changed files with 58 additions and 44 deletions

View File

@@ -1,6 +1,5 @@
import datetime
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from extras.models import Webhook
@@ -14,7 +13,10 @@ def enqueue_webhooks(instance, user, request_id, action):
Find Webhook(s) assigned to this instance + action and enqueue them
to be processed
"""
if instance._meta.label.lower() not in WEBHOOK_MODELS:
obj_type = ContentType.objects.get_for_model(instance.__class__)
webhook_models = ContentType.objects.filter(WEBHOOK_MODELS)
if obj_type not in webhook_models:
return
# Retrieve any applicable Webhooks
@@ -23,7 +25,6 @@ def enqueue_webhooks(instance, user, request_id, action):
ObjectChangeActionChoices.ACTION_UPDATE: 'type_update',
ObjectChangeActionChoices.ACTION_DELETE: 'type_delete',
}[action]
obj_type = ContentType.objects.get_for_model(instance.__class__)
webhooks = Webhook.objects.filter(obj_type=obj_type, enabled=True, **{action_flag: True})
if webhooks.exists():