workflows: add action to disable a formdef (#6973)

This commit is contained in:
Frédéric Péters 2015-04-17 14:57:18 +02:00
parent d478780713
commit a25f3fe541
2 changed files with 44 additions and 0 deletions

View File

@ -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()

27
wcs/wf/disable_formdef.py Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
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)