1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 06:51:10 +03:00

serialize notification body

This commit is contained in:
Jim Ladd 2019-08-14 11:00:58 -07:00
parent 24c3903c30
commit 3bb0aa4eec

View File

@ -4224,10 +4224,19 @@ class NotificationTemplateSerializer(BaseSerializer):
class NotificationSerializer(BaseSerializer): class NotificationSerializer(BaseSerializer):
body = serializers.SerializerMethodField(
help_text=_('Notification body')
)
class Meta: class Meta:
model = Notification model = Notification
fields = ('*', '-name', '-description', 'notification_template', 'error', 'status', 'notifications_sent', 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): def get_related(self, obj):
res = super(NotificationSerializer, self).get_related(obj) res = super(NotificationSerializer, self).get_related(obj)
@ -4236,6 +4245,15 @@ class NotificationSerializer(BaseSerializer):
)) ))
return res 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): class LabelSerializer(BaseSerializer):