1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Expose the role's content_type field and reorder the objects in the UI

when the resource was stored on ActivityStream as object1 instead of object2.

related #3841
This commit is contained in:
Jeff Bradberry 2019-05-10 14:13:37 -04:00
parent 0d3f1f4ac2
commit 250484339b
2 changed files with 21 additions and 9 deletions

View File

@ -128,7 +128,7 @@ SUMMARIZABLE_FK_FIELDS = {
'inventory_source': ('source', 'last_updated', 'status'), 'inventory_source': ('source', 'last_updated', 'status'),
'custom_inventory_script': DEFAULT_SUMMARY_FIELDS, 'custom_inventory_script': DEFAULT_SUMMARY_FIELDS,
'source_script': ('name', 'description'), 'source_script': ('name', 'description'),
'role': ('id', 'role_field'), 'role': ('id', 'role_field', 'content_type'),
'notification_template': DEFAULT_SUMMARY_FIELDS, 'notification_template': DEFAULT_SUMMARY_FIELDS,
'instance_group': {'id', 'name', 'controller_id'}, 'instance_group': {'id', 'name', 'controller_id'},
'insights_credential': DEFAULT_SUMMARY_FIELDS, 'insights_credential': DEFAULT_SUMMARY_FIELDS,
@ -5106,6 +5106,8 @@ class ActivityStreamSerializer(BaseSerializer):
for field in related_fields: for field in related_fields:
fval = getattr(thisItem, field, None) fval = getattr(thisItem, field, None)
if fval is not None: if fval is not None:
if field == 'content_type':
fval = str(fval)
thisItemDict[field] = fval thisItemDict[field] = fval
summary_fields[fk].append(thisItemDict) summary_fields[fk].append(thisItemDict)
except ObjectDoesNotExist: except ObjectDoesNotExist:

View File

@ -17,6 +17,16 @@ export default function BuildDescription(BuildAnchor, $log, i18n) {
switch(activity.object_association){ switch(activity.object_association){
// explicit role dis+associations // explicit role dis+associations
case 'role': case 'role':
var object1 = activity.object1;
var object2 = activity.object2;
// 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) {
object1 = activity.object2;
object2 = activity.object1;
}
// object1 field is resource targeted by the dis+association // object1 field is resource targeted by the dis+association
// object2 field is the resource the role is inherited from // object2 field is the resource the role is inherited from
// summary_field.role[0] contains ref info about the role // summary_field.role[0] contains ref info about the role
@ -24,23 +34,23 @@ export default function BuildDescription(BuildAnchor, $log, i18n) {
// expected outcome: "disassociated <object2> role_name from <object1>" // expected outcome: "disassociated <object2> role_name from <object1>"
case 'disassociate': case 'disassociate':
if (isGroupRelationship(activity)){ if (isGroupRelationship(activity)){
activity.description += BuildAnchor(activity.summary_fields.group[1], activity.object2, activity) + activity.summary_fields.role[0].role_field + activity.description += BuildAnchor(activity.summary_fields.group[1], object2, activity) + activity.summary_fields.role[0].role_field +
' from ' + BuildAnchor(activity.summary_fields.group[0], activity.object1, activity); ' from ' + BuildAnchor(activity.summary_fields.group[0], object1, activity);
} }
else{ else{
activity.description += BuildAnchor(activity.summary_fields[activity.object2][0], activity.object2, activity) + activity.summary_fields.role[0].role_field + activity.description += BuildAnchor(activity.summary_fields[object2][0], object2, activity) + activity.summary_fields.role[0].role_field +
' from ' + BuildAnchor(activity.summary_fields[activity.object1][0], activity.object1, activity); ' from ' + BuildAnchor(activity.summary_fields[object1][0], object1, activity);
} }
break; break;
// expected outcome: "associated <object2> role_name to <object1>" // expected outcome: "associated <object2> role_name to <object1>"
case 'associate': case 'associate':
if (isGroupRelationship(activity)){ if (isGroupRelationship(activity)){
activity.description += BuildAnchor(activity.summary_fields.group[1], activity.object2, activity) + activity.summary_fields.role[0].role_field + activity.description += BuildAnchor(activity.summary_fields.group[1], object2, activity) + activity.summary_fields.role[0].role_field +
' to ' + BuildAnchor(activity.summary_fields.group[0], activity.object1, activity); ' to ' + BuildAnchor(activity.summary_fields.group[0], object1, activity);
} }
else{ else{
activity.description += BuildAnchor(activity.summary_fields[activity.object2][0], activity.object2, activity) + activity.summary_fields.role[0].role_field + activity.description += BuildAnchor(activity.summary_fields[object2][0], object2, activity) + activity.summary_fields.role[0].role_field +
' to ' + BuildAnchor(activity.summary_fields[activity.object1][0], activity.object1, activity); ' to ' + BuildAnchor(activity.summary_fields[object1][0], object1, activity);
} }
break; break;
} }