diff --git a/awx/api/serializers.py b/awx/api/serializers.py index cb05e615dd..5899b9af77 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -128,7 +128,7 @@ SUMMARIZABLE_FK_FIELDS = { 'inventory_source': ('source', 'last_updated', 'status'), 'custom_inventory_script': DEFAULT_SUMMARY_FIELDS, 'source_script': ('name', 'description'), - 'role': ('id', 'role_field', 'content_type'), + 'role': ('id', 'role_field'), 'notification_template': DEFAULT_SUMMARY_FIELDS, 'instance_group': {'id', 'name', 'controller_id'}, 'insights_credential': DEFAULT_SUMMARY_FIELDS, @@ -4956,6 +4956,7 @@ class ActivityStreamSerializer(BaseSerializer): changes = serializers.SerializerMethodField() object_association = serializers.SerializerMethodField() + object_type = serializers.SerializerMethodField() @cached_property def _local_summarizable_fk_fields(self): @@ -4980,8 +4981,8 @@ class ActivityStreamSerializer(BaseSerializer): class Meta: model = ActivityStream - fields = ('*', '-name', '-description', '-created', '-modified', - 'timestamp', 'operation', 'changes', 'object1', 'object2', 'object_association') + fields = ('*', '-name', '-description', '-created', '-modified', 'timestamp', 'operation', + 'changes', 'object1', 'object2', 'object_association', 'object_type') def get_fields(self): ret = super(ActivityStreamSerializer, self).get_fields() @@ -5024,6 +5025,21 @@ class ActivityStreamSerializer(BaseSerializer): logger.debug('Failed to parse activity stream relationship type {}'.format(obj.object_relationship_type)) return "" + def get_object_type(self, obj): + if not obj.object_relationship_type: + return "" + elif obj.object_relationship_type.endswith('_role'): + return camelcase_to_underscore(obj.object_relationship_type.rsplit('.', 2)[-2]) + # default case: these values look like + # "awx.main.models.organization.Organization_notification_templates_success" + # so we have to take after the last period but before the first underscore. + try: + cls = obj.object_relationship_type.rsplit('.', 1)[0] + return camelcase_to_underscore(cls.split('_', 1)) + except Exception: + logger.debug('Failed to parse activity stream relationship type {}'.format(obj.object_relationship_type)) + return "" + def get_related(self, obj): rel = {} if obj.actor is not None: @@ -5106,8 +5122,6 @@ class ActivityStreamSerializer(BaseSerializer): for field in related_fields: fval = getattr(thisItem, field, None) if fval is not None: - if field == 'content_type': - fval = str(fval) thisItemDict[field] = fval summary_fields[fk].append(thisItemDict) except ObjectDoesNotExist: diff --git a/awx/ui/client/src/activity-stream/factories/build-description.factory.js b/awx/ui/client/src/activity-stream/factories/build-description.factory.js index 93c1e41593..ddb05b0662 100644 --- a/awx/ui/client/src/activity-stream/factories/build-description.factory.js +++ b/awx/ui/client/src/activity-stream/factories/build-description.factory.js @@ -22,7 +22,7 @@ export default function BuildDescription(BuildAnchor, $log, i18n) { // if object1 winds up being the role's resource, we need to swap the objects // in order to make the sentence make sense. - if (activity.summary_fields.role[0].content_type === object1) { + if (activity.object_type === object1) { object1 = activity.object2; object2 = activity.object1; }