From 49f4ed10cae4d4a61845aac31f3393523b7934fb Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Wed, 14 Nov 2018 10:01:08 -0500 Subject: [PATCH] include M2M labels and credentials in Job creation activity stream --- awx/main/models/unified_jobs.py | 14 ++++++++++++-- awx/main/signals.py | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index ba9d51258e..713ef68f0e 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -374,7 +374,12 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio unified_job.survey_passwords = new_job_passwords kwargs['survey_passwords'] = new_job_passwords # saved in config object for relaunch - unified_job.save() + from awx.main.signals import disable_activity_stream, activity_stream_create + with disable_activity_stream(): + # Don't emit the activity stream record here for creation, + # because we haven't attached important M2M relations yet, like + # credentials and labels + unified_job.save() # Labels and credentials copied here if validated_kwargs.get('credentials'): @@ -386,7 +391,6 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio validated_kwargs['credentials'] = [cred for cred in cred_dict.values()] kwargs['credentials'] = validated_kwargs['credentials'] - from awx.main.signals import disable_activity_stream with disable_activity_stream(): copy_m2m_relationships(self, unified_job, fields, kwargs=validated_kwargs) @@ -397,6 +401,12 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio # Create record of provided prompts for relaunch and rescheduling unified_job.create_config_from_prompts(kwargs, parent=self) + # manually issue the create activity stream entry _after_ M2M relations + # have been associated to the UJ + from awx.main.models import SystemJob + if not isinstance(unified_job, SystemJob): + activity_stream_create(None, unified_job, True) + return unified_job @classmethod diff --git a/awx/main/signals.py b/awx/main/signals.py index d0b472417a..82eb41e18a 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -425,6 +425,11 @@ def activity_stream_create(sender, instance, created, **kwargs): changes = model_to_dict(instance, model_serializer_mapping) # Special case where Job survey password variables need to be hidden if type(instance) == Job: + changes['credentials'] = [ + six.text_type('{} ({})').format(c.name, c.id) + for c in instance.credentials.iterator() + ] + changes['labels'] = [l.name for l in instance.labels.iterator()] if 'extra_vars' in changes: changes['extra_vars'] = instance.display_extra_vars() if type(instance) == OAuth2AccessToken: