From 02aa35840b00e056c6c6949b5695db7b0b581015 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 4 Dec 2015 11:55:06 +0100 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(-) diff --git a/wcs/formdata.py b/wcs/formdata.py index fef4294..0ecf864 100644 --- a/wcs/formdata.py +++ b/wcs/formdata.py @@ -601,7 +601,7 @@ class FormData(StorableObject): evo.parts = None self.store() - def get_json_export_dict(self, include_files=True): + def get_json_export_dict(self, include_files=True, anonymised=False): data = {} data['id'] = '%s/%s' % (self.formdef.url_name, self.id) data['display_id'] = self.get_display_id() @@ -612,29 +612,31 @@ class FormData(StorableObject): data['last_update_time'] = self.last_update_time data['url'] = self.get_url() - try: - user = get_publisher().user_class.get(self.user_id) - except KeyError: - user = None - # this is custom code so it is possible to mark forms as anonyms, this - # is done through the VoteAnonymity field, this is very specific but - # isn't generalised yet into an useful extension mechanism, as it's not - # clear at the moment what could be useful. - for f in self.formdef.fields: - if f.key == 'vote-anonymity': + if not anonymised: + try: + user = get_publisher().user_class.get(self.user_id) + except KeyError: user = None - break - if user: - data['user'] = {'id': user.id, 'name': user.display_name} + # this is custom code so it is possible to mark forms as anonyms, this + # is done through the VoteAnonymity field, this is very specific but + # isn't generalised yet into an useful extension mechanism, as it's not + # clear at the moment what could be useful. + for f in self.formdef.fields: + if f.key == 'vote-anonymity': + user = None + break + if user: + data['user'] = {'id': user.id, 'name': user.display_name} data['fields'] = get_json_dict(self.formdef.fields, self.data, - include_files=include_files) + include_files=include_files, anonymised=anonymised) data['workflow'] = {} wf_status = self.get_visible_status() if wf_status: data['workflow']['status'] = {'id': wf_status.id, 'name': wf_status.name} - if self.workflow_data: + # Workflow data have unknown purpose, do not store then in anonymised export + if self.workflow_data and not anonymised: data['workflow']['data'] = self.workflow_data # add a roles dictionary, with workflow functions and two special -- 2.1.4