diff --git a/awx/api/serializers.py b/awx/api/serializers.py index bb2db24313..13bfbd982c 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1006,7 +1006,8 @@ class ActivityStreamSerializer(BaseSerializer): class Meta: model = ActivityStream - fields = ('id', 'url', 'related', 'summary_fields', 'timestamp', 'operation', 'changes') + fields = ('id', 'url', 'related', 'summary_fields', 'timestamp', 'operation', 'changes', + 'object1_id', 'object1_type', 'object2_id', 'object2_type', 'object_relationship_type') def get_related(self, obj): if obj is None: @@ -1015,10 +1016,10 @@ class ActivityStreamSerializer(BaseSerializer): if obj.user is not None: rel['user'] = reverse('api:user_detail', args=(obj.user.pk,)) obj1_resolution = camelcase_to_underscore(obj.object1_type.split(".")[-1]) - rel['object_1'] = reverse('api:' + obj1_resolution + '_detail', args=(obj.object1_id,)) + rel['object1'] = reverse('api:' + obj1_resolution + '_detail', args=(obj.object1_id,)) if obj.operation in ('associate', 'disassociate'): obj2_resolution = camelcase_to_underscore(obj.object2_type.split(".")[-1]) - rel['object_2'] = reverse('api:' + obj2_resolution + '_detail', args=(obj.object2_id,)) + rel['object2'] = reverse('api:' + obj2_resolution + '_detail', args=(obj.object2_id,)) return rel def get_summary_fields(self, obj): @@ -1026,14 +1027,24 @@ class ActivityStreamSerializer(BaseSerializer): return {} d = super(ActivityStreamSerializer, self).get_summary_fields(obj) try: + short_obj_type = obj.object1_type.split(".")[-1] + under_short_obj_type = camelcase_to_underscore(short_obj_type) obj1 = eval(obj.object1_type + ".objects.get(id=" + str(obj.object1_id) + ")") - d['object1'] = {'name': obj1.name, 'description': obj1.description} + d['object1'] = {'name': obj1.name, 'description': obj1.description, + 'base': under_short_obj_type, 'id': obj.object1_id} + if under_short_obj_type == "host" or under_short_obj_type == "group": + d['inventory'] = {'name': obj1.inventory.name, 'id': obj1.inventory.id} except Exception, e: logger.error("Error getting object 1 summary: " + str(e)) try: + short_obj_type = obj.object2_type.split(".")[-1] + under_short_obj_type = camelcase_to_underscore(short_obj_type) if obj.operation in ('associate', 'disassociate'): - obj2 = eval(obj.object1_type + ".objects.get(id=" + str(obj.object2_id) + ")") - d['object2'] = {'name': obj2.name, 'description': obj2.description} + obj2 = eval(obj.object2_type + ".objects.get(id=" + str(obj.object2_id) + ")") + d['object2'] = {'name': obj2.name, 'description': obj2.description, + 'base': under_short_obj_type, 'id': obj.object2_id} + if under_short_obj_type == "host" or under_short_obj_type == "group": + d['inventory'] = {'name': obj2.inventory.name, 'id': obj2.inventory.id} except Exception, e: logger.error("Error getting object 2 summary: " + str(e)) return d