wcs/wcs/wf/anonymise.py

58 lines
2.1 KiB
Python

# w.c.s. - web application for online forms
# Copyright (C) 2005-2011 Entr'ouvert
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
from quixote import get_request, get_session
from wcs.qommon import _
from wcs.qommon.form import CheckboxWidget
from wcs.workflows import WorkflowStatusItem, register_item_class
class AnonymiseWorkflowStatusItem(WorkflowStatusItem):
description = _('Anonymisation')
key = 'anonymise'
category = 'formdata-action'
unlink_user = False
def perform(self, formdata):
if self.unlink_user is True:
if formdata.is_submitter(get_request().user):
get_session().mark_anonymous_formdata(formdata)
formdata.unlink_user()
formdata.remove_tracking_code()
else:
formdata.anonymise()
def get_parameters(self):
return ('unlink_user',)
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None, **kwargs):
super().add_parameters_widgets(form, parameters, prefix, formdef, **kwargs)
if 'unlink_user' in parameters:
form.add(
CheckboxWidget,
'%sunlink_user' % prefix,
title=_('Only perform form/card user unlinking'),
hint=_(
'If checked, this action will only unlink user from the form/card. '
'If existing, the tracking code will be deleted.'
),
value=self.unlink_user,
)
register_item_class(AnonymiseWorkflowStatusItem)