1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

NotificationSerializer should gracefully handle webhook/pagerduty bodies

This commit is contained in:
Jim Ladd 2019-10-17 23:51:55 -07:00 committed by Ryan Petrello
parent 1e9173e8ef
commit 12d735ec8f
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777

View File

@ -4514,8 +4514,18 @@ class NotificationSerializer(BaseSerializer):
'notification_type', 'recipients', 'subject', 'body')
def get_body(self, obj):
if obj.notification_type == 'webhook' and 'body' in obj.body:
return obj.body['body']
if obj.notification_type in ('webhook', 'pagerduty'):
if isinstance(obj.body, dict):
if 'body' in obj.body:
return obj.body['body']
elif isinstance(obj.body, str):
# attempt to load json string
try:
potential_body = json.loads(obj.body)
if isinstance(potential_body, dict) and 'body' in potential_body:
return potential_body['body']
except json.JSONDecodeError:
pass
return obj.body
def get_related(self, obj):