From 5de321ae7a5c61df68596dd5b91103770c6a678a Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Fri, 20 Jul 2018 12:40:12 -0400 Subject: [PATCH] write special cases for object_association field --- awx/api/serializers.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 1fb9a43f72..d4a38e43f2 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -4789,11 +4789,21 @@ class ActivityStreamSerializer(BaseSerializer): return {} def get_object_association(self, obj): + if not obj.object_relationship_type: + return "" + elif obj.object_relationship_type.endswith('_role'): + # roles: these values look like + # "awx.main.models.inventory.Inventory.admin_role" + # due to historical reasons the UI expects just "role" here + return "role" + # default case: these values look like + # "awx.main.models.organization.Organization_notification_templates_success" + # so instead of splitting on period we have to take after the first underscore try: - return obj.object_relationship_type.split(".")[-1].split("_")[1] + return obj.object_relationship_type.split(".")[-1].split("_", 1)[1] except Exception: - pass - return "" + logger.debug('Failed to parse activity stream relationship type {}'.format(obj.object_relationship_type)) + return "" def get_related(self, obj): rel = {}