Projet

Général

Profil

0002-formdata-add-anonymised-parameter-to-get_json_export.patch

Benjamin Dauvergne, 04 décembre 2015 11:58

Télécharger (3,08 ko)

Voir les différences:

Subject: [PATCH 2/2] formdata: add anonymised parameter to
 get_json_export_dict

Parameter is passed the get_json_dict() and prevents user and workflow_data to be
included in the export.
 wcs/formdata.py | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
wcs/formdata.py
601 601
                evo.parts = None
602 602
        self.store()
603 603

  
604
    def get_json_export_dict(self, include_files=True):
604
    def get_json_export_dict(self, include_files=True, anonymised=False):
605 605
        data = {}
606 606
        data['id'] = '%s/%s' % (self.formdef.url_name, self.id)
607 607
        data['display_id'] = self.get_display_id()
......
612 612
        data['last_update_time'] = self.last_update_time
613 613
        data['url'] = self.get_url()
614 614

  
615
        try:
616
            user = get_publisher().user_class.get(self.user_id)
617
        except KeyError:
618
            user = None
619
        # this is custom code so it is possible to mark forms as anonyms, this
620
        # is done through the VoteAnonymity field, this is very specific but
621
        # isn't generalised yet into an useful extension mechanism, as it's not
622
        # clear at the moment what could be useful.
623
        for f in self.formdef.fields:
624
            if f.key == 'vote-anonymity':
615
        if not anonymised:
616
            try:
617
                user = get_publisher().user_class.get(self.user_id)
618
            except KeyError:
625 619
                user = None
626
                break
627
        if user:
628
            data['user'] = {'id': user.id, 'name': user.display_name}
620
            # this is custom code so it is possible to mark forms as anonyms, this
621
            # is done through the VoteAnonymity field, this is very specific but
622
            # isn't generalised yet into an useful extension mechanism, as it's not
623
            # clear at the moment what could be useful.
624
            for f in self.formdef.fields:
625
                if f.key == 'vote-anonymity':
626
                    user = None
627
                    break
628
            if user:
629
                data['user'] = {'id': user.id, 'name': user.display_name}
629 630

  
630 631
        data['fields'] = get_json_dict(self.formdef.fields, self.data,
631
                include_files=include_files)
632
                include_files=include_files, anonymised=anonymised)
632 633

  
633 634
        data['workflow'] = {}
634 635
        wf_status = self.get_visible_status()
635 636
        if wf_status:
636 637
            data['workflow']['status'] = {'id': wf_status.id, 'name': wf_status.name}
637
        if self.workflow_data:
638
        # Workflow data have unknown purpose, do not store then in anonymised export
639
        if self.workflow_data and not anonymised:
638 640
            data['workflow']['data'] = self.workflow_data
639 641

  
640 642
        # add a roles dictionary, with workflow functions and two special
641
-