From 3bb0aa4eeccebaded07e9c71a54f77fdfd9117de Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Wed, 14 Aug 2019 11:00:58 -0700 Subject: [PATCH] serialize notification body --- awx/api/serializers.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 3e2067f6b5..8c539c5966 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -4224,10 +4224,19 @@ class NotificationTemplateSerializer(BaseSerializer): class NotificationSerializer(BaseSerializer): + body = serializers.SerializerMethodField( + help_text=_('Notification body') + ) + class Meta: model = Notification fields = ('*', '-name', '-description', 'notification_template', 'error', 'status', 'notifications_sent', - 'notification_type', 'recipients', 'subject') + 'notification_type', 'recipients', 'subject', 'body') + + def get_body(self, obj): + if obj.notification_type == 'webhook' and 'body' in obj.body: + return obj.body['body'] + return obj.body def get_related(self, obj): res = super(NotificationSerializer, self).get_related(obj) @@ -4236,6 +4245,15 @@ class NotificationSerializer(BaseSerializer): )) return res + def to_representation(self, obj): + ret = super(NotificationSerializer, self).to_representation(obj) + + if obj.notification_type == 'webhook': + ret.pop('subject') + if obj.notification_type not in ('email', 'webhook', 'pagerduty'): + ret.pop('body') + return ret + class LabelSerializer(BaseSerializer):