always escalete object

This commit is contained in:
Matthias 2021-10-19 00:32:26 +02:00
parent 515e1faad4
commit bf679f185f
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -17,6 +17,7 @@ from rest_framework.exceptions import NotAcceptable, NotFound
from django_q.tasks import async_task from django_q.tasks import async_task
from .models import WebhookEndpoint, WebhookMessage from .models import WebhookEndpoint, WebhookMessage
from InvenTree.helpers import inheritors
class CsrfExemptMixin(object): class CsrfExemptMixin(object):
@ -69,10 +70,18 @@ class WebhookView(CsrfExemptMixin, APIView):
message.worked_on = process_result message.worked_on = process_result
message.save() message.save()
def _escalate_object(self, obj):
classes = inheritors(obj.__class__)
for cls in classes:
mdl_name = cls._meta.model_name
if hasattr(obj, mdl_name):
return getattr(obj, mdl_name)
return obj
def _get_webhook(self, endpoint, request, *args, **kwargs): def _get_webhook(self, endpoint, request, *args, **kwargs):
try: try:
webhook = self.model_class.objects.get(endpoint_id=endpoint) webhook = self.model_class.objects.get(endpoint_id=endpoint)
self.webhook = webhook self.webhook = self._escalate_object(webhook)
self.webhook.init(request, *args, **kwargs) self.webhook.init(request, *args, **kwargs)
return self.webhook.process_webhook() return self.webhook.process_webhook()
except self.model_class.DoesNotExist: except self.model_class.DoesNotExist: