Skip to content

Commit

Permalink
Merge branch 'hotfix/19.29.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mfraezz committed Oct 4, 2019
2 parents 12539c1 + 7d66e22 commit 9af2129
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions api/registrations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ def anonymize_registered_meta(self, obj):
for question in page['questions']:
if question['title'] in ANONYMIZED_TITLES and meta_values.get(question.get('qid')):
del meta_values[question['qid']]

strip_registered_meta_comments(meta_values)
return meta_values

def check_admin_perms(self, registration, user, validated_data):
Expand Down Expand Up @@ -619,3 +621,33 @@ class RegistrationStorageProviderSerializer(NodeStorageProviderSerializer):
kind='folder',
never_embed=True,
)

def strip_registered_meta_comments(messy_dict_or_list):
"""Removes Prereg Challenge comments from a given `registered_meta` dict.
Nothing that uses APIv2 needs these comments:
```
{
"registered_meta": {
"q20": {
"comments": [ ... ], <~~~ THIS
"value": "foo",
"extra": []
},
}
}
```
"""
if isinstance(messy_dict_or_list, list):
for obj in messy_dict_or_list:
strip_registered_meta_comments(obj)
elif isinstance(messy_dict_or_list, dict):
comments = messy_dict_or_list.get('comments', None)

# some schemas have a question named "comments" -- those will have a dict value
if isinstance(comments, list):
del messy_dict_or_list['comments']

# dig into the deeply nested structure
for nested_obj in messy_dict_or_list.values():
strip_registered_meta_comments(nested_obj)

0 comments on commit 9af2129

Please sign in to comment.