From 7a017aec980afe7d8b22ba24731cc75a23fe2f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 17 Apr 2015 14:57:18 +0200 Subject: [PATCH] workflows: add action to disable a formdef (#6973) --- tests/test_workflows.py | 17 +++++++++++++++++ wcs/wf/disable_formdef.py | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 wcs/wf/disable_formdef.py diff --git a/tests/test_workflows.py b/tests/test_workflows.py index df6fd69..09ffc9a 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -12,6 +12,7 @@ from wcs.roles import Role from wcs.workflows import (Workflow, WorkflowStatusItem, SendmailWorkflowStatusItem, SendSMSWorkflowStatusItem) from wcs.wf.anonymise import AnonymiseWorkflowStatusItem +from wcs.wf.disable_formdef import DisableFormdefStatusItem from wcs.wf.dispatch import DispatchWorkflowStatusItem from wcs.wf.jump import JumpWorkflowStatusItem, _apply_timeouts from wcs.wf.register_comment import RegisterCommenterWorkflowStatusItem @@ -490,3 +491,19 @@ def test_sms(): item.perform(formdata) # nothing assert sms_mocking.sms[-1]['destinations'] == ['000'] assert sms_mocking.sms[-1]['text'] == 'XXX' + +def test_disable_formdef(): + formdef = FormDef() + formdef.name = 'baz' + formdef.fields = [] + formdef.store() + + formdata = formdef.data_class()() + formdata.just_created() + formdata.user_id = '1' + formdata.store() + + item = DisableFormdefStatusItem() + assert not FormDef.get(formdef.id).is_disabled() + item.perform(formdata) + assert FormDef.get(formdef.id).is_disabled() diff --git a/wcs/wf/disable_formdef.py b/wcs/wf/disable_formdef.py new file mode 100644 index 0000000..6bb4c1c --- /dev/null +++ b/wcs/wf/disable_formdef.py @@ -0,0 +1,27 @@ +# w.c.s. - web application for online forms +# Copyright (C) 2005-2015 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 . + +from wcs.workflows import WorkflowStatusItem, register_item_class + +class DisableFormdefStatusItem(WorkflowStatusItem): + description = N_('Disable Form') + key = 'disable_form' + + def perform(self, formdata): + formdata.formdef.disabled = True + formdata.formdef.store() + +register_item_class(DisableFormdefStatusItem) -- 2.1.4