|
23 | 23 | from framework.auth.core import Auth
|
24 | 24 | from osf.exceptions import ValidationValueError, NodeStateError
|
25 | 25 | from osf.models import Node, RegistrationSchema
|
| 26 | +from osf.utils.registrations import strip_registered_meta_comments |
26 | 27 | from website.settings import ANONYMIZED_TITLES
|
27 | 28 | from framework.sentry import log_exception
|
28 | 29 |
|
@@ -387,15 +388,15 @@ def anonymize_registered_meta(self, obj):
|
387 | 388 | matching ANONYMIZED_TITLES. If present, deletes that question's response
|
388 | 389 | from meta_values.
|
389 | 390 | """
|
390 |
| - meta_values = obj.registered_meta.values()[0] |
| 391 | + meta_values = strip_registered_meta_comments(obj.registered_meta.values()[0]) |
| 392 | + |
391 | 393 | if is_anonymized(self.context['request']):
|
392 | 394 | registration_schema = RegistrationSchema.objects.get(_id=obj.registered_schema_id)
|
393 | 395 | for page in registration_schema.schema['pages']:
|
394 | 396 | for question in page['questions']:
|
395 | 397 | if question['title'] in ANONYMIZED_TITLES and meta_values.get(question.get('qid')):
|
396 | 398 | del meta_values[question['qid']]
|
397 | 399 |
|
398 |
| - strip_registered_meta_comments(meta_values) |
399 | 400 | return meta_values
|
400 | 401 |
|
401 | 402 | def check_admin_perms(self, registration, user, validated_data):
|
@@ -621,33 +622,3 @@ class RegistrationStorageProviderSerializer(NodeStorageProviderSerializer):
|
621 | 622 | kind='folder',
|
622 | 623 | never_embed=True,
|
623 | 624 | )
|
624 |
| - |
625 |
| -def strip_registered_meta_comments(messy_dict_or_list): |
626 |
| - """Removes Prereg Challenge comments from a given `registered_meta` dict. |
627 |
| -
|
628 |
| - Nothing that uses APIv2 needs these comments: |
629 |
| - ``` |
630 |
| - { |
631 |
| - "registered_meta": { |
632 |
| - "q20": { |
633 |
| - "comments": [ ... ], <~~~ THIS |
634 |
| - "value": "foo", |
635 |
| - "extra": [] |
636 |
| - }, |
637 |
| - } |
638 |
| - } |
639 |
| - ``` |
640 |
| - """ |
641 |
| - if isinstance(messy_dict_or_list, list): |
642 |
| - for obj in messy_dict_or_list: |
643 |
| - strip_registered_meta_comments(obj) |
644 |
| - elif isinstance(messy_dict_or_list, dict): |
645 |
| - comments = messy_dict_or_list.get('comments', None) |
646 |
| - |
647 |
| - # some schemas have a question named "comments" -- those will have a dict value |
648 |
| - if isinstance(comments, list): |
649 |
| - del messy_dict_or_list['comments'] |
650 |
| - |
651 |
| - # dig into the deeply nested structure |
652 |
| - for nested_obj in messy_dict_or_list.values(): |
653 |
| - strip_registered_meta_comments(nested_obj) |
0 commit comments