Merge pull request #2290 from lampwins/bug/2137

Force webhooks to use the same JSONEncoder class as DRF - fixes #2137
This commit is contained in:
Jeremy Stretch 2018-08-01 12:57:05 -04:00 committed by GitHub
commit 5e5b9683f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,10 @@
import hashlib import hashlib
import hmac import hmac
import requests import requests
import json
from django_rq import job from django_rq import job
from rest_framework.utils.encoders import JSONEncoder
from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED, OBJECTCHANGE_ACTION_CHOICES from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED, OBJECTCHANGE_ACTION_CHOICES
@ -13,9 +15,9 @@ def process_webhook(webhook, data, model_class, event, timestamp):
Make a POST request to the defined Webhook Make a POST request to the defined Webhook
""" """
payload = { payload = {
'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event], 'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event].lower(),
'timestamp': timestamp, 'timestamp': timestamp,
'model': model_class.__name__, 'model': model_class._meta.model_name,
'data': data 'data': data
} }
headers = { headers = {
@ -28,7 +30,7 @@ def process_webhook(webhook, data, model_class, event, timestamp):
} }
if webhook.http_content_type == WEBHOOK_CT_JSON: if webhook.http_content_type == WEBHOOK_CT_JSON:
params.update({'json': payload}) params.update({'data': json.dumps(payload, cls=JSONEncoder)})
elif webhook.http_content_type == WEBHOOK_CT_X_WWW_FORM_ENCODED: elif webhook.http_content_type == WEBHOOK_CT_X_WWW_FORM_ENCODED:
params.update({'data': payload}) params.update({'data': payload})