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

Merge pull request #2625 from AlanCoding/just_role

Write special cases for object_association field
This commit is contained in:
Alan Rominger 2018-07-24 07:46:22 -04:00 committed by GitHub
commit f0252f67dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4791,11 +4791,21 @@ class ActivityStreamSerializer(BaseSerializer):
return {} return {}
def get_object_association(self, obj): 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: try:
return obj.object_relationship_type.split(".")[-1].split("_")[1] return obj.object_relationship_type.split(".")[-1].split("_", 1)[1]
except Exception: except Exception:
pass logger.debug('Failed to parse activity stream relationship type {}'.format(obj.object_relationship_type))
return "" return ""
def get_related(self, obj): def get_related(self, obj):
rel = {} rel = {}