mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 18:09:57 -03:30
WFJT activity stream optimization
This commit is contained in:
parent
77f0625d44
commit
3b4af0aa82
@ -83,6 +83,8 @@ SUMMARIZABLE_FK_FIELDS = {
|
||||
'network_credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'net'),
|
||||
'job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'elapsed'),
|
||||
'job_template': DEFAULT_SUMMARY_FIELDS,
|
||||
'workflow_job_template': DEFAULT_SUMMARY_FIELDS,
|
||||
'workflow_job': DEFAULT_SUMMARY_FIELDS,
|
||||
'schedule': DEFAULT_SUMMARY_FIELDS + ('next_run',),
|
||||
'unified_job_template': DEFAULT_SUMMARY_FIELDS + ('unified_job_type',),
|
||||
'last_job': DEFAULT_SUMMARY_FIELDS + ('finished', 'status', 'failed', 'license_error'),
|
||||
@ -2999,13 +3001,17 @@ class ActivityStreamSerializer(BaseSerializer):
|
||||
rel = {}
|
||||
if obj.actor is not None:
|
||||
rel['actor'] = reverse('api:user_detail', args=(obj.actor.pk,))
|
||||
for fk, __ in SUMMARIZABLE_FK_FIELDS.items() + [('workflow_job_template', 0)]:
|
||||
for fk, __ in SUMMARIZABLE_FK_FIELDS.items():
|
||||
if not hasattr(obj, fk):
|
||||
continue
|
||||
allm2m = getattr(obj, fk).all()
|
||||
if getattr(obj, fk).exists():
|
||||
rel[fk] = []
|
||||
id_list = []
|
||||
for thisItem in allm2m:
|
||||
if getattr(thisItem, 'id', None) in id_list:
|
||||
continue
|
||||
id_list.append(getattr(thisItem, 'id', None))
|
||||
if fk == 'custom_inventory_script':
|
||||
rel[fk].append(reverse('api:inventory_script_detail', args=(thisItem.id,)))
|
||||
else:
|
||||
@ -3017,7 +3023,7 @@ class ActivityStreamSerializer(BaseSerializer):
|
||||
|
||||
def get_summary_fields(self, obj):
|
||||
summary_fields = OrderedDict()
|
||||
for fk, related_fields in SUMMARIZABLE_FK_FIELDS.items() + [('workflow_job_template', DEFAULT_SUMMARY_FIELDS)]:
|
||||
for fk, related_fields in SUMMARIZABLE_FK_FIELDS.items():
|
||||
try:
|
||||
if not hasattr(obj, fk):
|
||||
continue
|
||||
@ -3050,6 +3056,9 @@ class ActivityStreamSerializer(BaseSerializer):
|
||||
thisItemDict[field] = fval
|
||||
if fk == 'group':
|
||||
thisItemDict['inventory_id'] = getattr(thisItem, 'inventory_id', None)
|
||||
if thisItemDict.get('id', None):
|
||||
if thisItemDict.get('id', None) in [obj_dict.get('id', None) for obj_dict in summary_fields[fk]]:
|
||||
continue
|
||||
summary_fields[fk].append(thisItemDict)
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
||||
@ -3087,6 +3087,13 @@ class WorkflowJobTemplateActivityStreamList(WorkflowsEnforcementMixin, ActivityS
|
||||
relationship = 'activitystream_set'
|
||||
new_in_310 = True
|
||||
|
||||
def get_queryset(self):
|
||||
parent = self.get_parent_object()
|
||||
self.check_parent_access(parent)
|
||||
qs = self.request.user.get_queryset(self.model)
|
||||
return qs.filter(Q(workflow_job_template=parent) |
|
||||
Q(workflow_job_template_node__workflow_job_template=parent))
|
||||
|
||||
|
||||
class WorkflowJobList(WorkflowsEnforcementMixin, ListCreateAPIView):
|
||||
|
||||
|
||||
@ -2104,10 +2104,10 @@ class ActivityStreamAccess(BaseAccess):
|
||||
qs = self.model.objects.all()
|
||||
qs = qs.prefetch_related('organization', 'user', 'inventory', 'host', 'group', 'inventory_source',
|
||||
'inventory_update', 'credential', 'team', 'project', 'project_update',
|
||||
'permission', 'job_template', 'job', 'ad_hoc_command',
|
||||
'job_template', 'job', 'ad_hoc_command',
|
||||
'notification_template', 'notification', 'label', 'role', 'actor',
|
||||
'schedule', 'role', 'custom_inventory_script', 'unified_job_template',
|
||||
'workflow_job_template')
|
||||
'schedule', 'custom_inventory_script', 'unified_job_template',
|
||||
'workflow_job_template', 'workflow_job')
|
||||
if self.user.is_superuser or self.user.is_system_auditor:
|
||||
return qs.all()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user