mirror of
https://github.com/ansible/awx.git
synced 2026-03-09 21:49:27 -02:30
Merge pull request #2682 from ryanpetrello/job-m2m-activity-stream
include M2M labels and credentials in Job creation activity stream Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -374,7 +374,12 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
|||||||
unified_job.survey_passwords = new_job_passwords
|
unified_job.survey_passwords = new_job_passwords
|
||||||
kwargs['survey_passwords'] = new_job_passwords # saved in config object for relaunch
|
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
|
# Labels and credentials copied here
|
||||||
if validated_kwargs.get('credentials'):
|
if validated_kwargs.get('credentials'):
|
||||||
@@ -386,7 +391,6 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
|||||||
validated_kwargs['credentials'] = [cred for cred in cred_dict.values()]
|
validated_kwargs['credentials'] = [cred for cred in cred_dict.values()]
|
||||||
kwargs['credentials'] = validated_kwargs['credentials']
|
kwargs['credentials'] = validated_kwargs['credentials']
|
||||||
|
|
||||||
from awx.main.signals import disable_activity_stream
|
|
||||||
with disable_activity_stream():
|
with disable_activity_stream():
|
||||||
copy_m2m_relationships(self, unified_job, fields, kwargs=validated_kwargs)
|
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
|
# Create record of provided prompts for relaunch and rescheduling
|
||||||
unified_job.create_config_from_prompts(kwargs, parent=self)
|
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
|
return unified_job
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -425,6 +425,11 @@ def activity_stream_create(sender, instance, created, **kwargs):
|
|||||||
changes = model_to_dict(instance, model_serializer_mapping)
|
changes = model_to_dict(instance, model_serializer_mapping)
|
||||||
# Special case where Job survey password variables need to be hidden
|
# Special case where Job survey password variables need to be hidden
|
||||||
if type(instance) == Job:
|
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:
|
if 'extra_vars' in changes:
|
||||||
changes['extra_vars'] = instance.display_extra_vars()
|
changes['extra_vars'] = instance.display_extra_vars()
|
||||||
if type(instance) == OAuth2AccessToken:
|
if type(instance) == OAuth2AccessToken:
|
||||||
|
|||||||
Reference in New Issue
Block a user