render survey_spec for display purposes in a safe manner

survey_spec is a nested dict, so if we don't `deepcopy()` it, updates
to the individual fields could corrupt the original data structure;
this was causing a bug whereby activity stream updates converted
encrypted survey password defaults -> `$encrypted$`, but inadvertently
modified the originating model due to shared references

see: https://github.com/ansible/ansible-tower/issues/7769
This commit is contained in:
Ryan Petrello 2017-11-13 13:01:56 -05:00
parent bc705ad8ce
commit be00b1ca96
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777

View File

@ -1,6 +1,6 @@
# Python
import json
from copy import copy
from copy import copy, deepcopy
# Django
from django.db import models
@ -257,7 +257,7 @@ class SurveyJobTemplateMixin(models.Model):
'''
Hide encrypted default passwords in survey specs
'''
survey_spec = self.survey_spec.copy() if self.survey_spec else {}
survey_spec = deepcopy(self.survey_spec) if self.survey_spec else {}
for field in survey_spec.get('spec', []):
if field.get('type') == 'password':
if 'default' in field and field['default']: