admin: check also linked CardDef when deleting a workflow (#46587)
This commit is contained in:
parent
a1c510fbe2
commit
f24963ed05
|
@ -20,6 +20,7 @@ from wcs.wf.export_to_model import ExportToModel
|
|||
from wcs.wf.jump import JumpWorkflowStatusItem
|
||||
from wcs.wf.register_comment import RegisterCommenterWorkflowStatusItem
|
||||
from wcs.wf.wscall import WebserviceCallStatusItem
|
||||
from wcs.carddef import CardDef
|
||||
from wcs.formdef import FormDef
|
||||
from wcs import fields
|
||||
|
||||
|
@ -251,9 +252,34 @@ def test_workflows_delete(pub):
|
|||
workflow = Workflow(name='foo')
|
||||
workflow.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/workflows/1/')
|
||||
formdef = FormDef()
|
||||
formdef.name = 'Form title'
|
||||
formdef.workflow = workflow
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
|
||||
resp = app.get('/backoffice/workflows/1/')
|
||||
resp = resp.click(href='delete')
|
||||
assert 'This workflow is currently in use, you cannot remove it.' in resp.text
|
||||
|
||||
formdef.remove_self()
|
||||
|
||||
carddef = CardDef()
|
||||
carddef.name = 'Card title'
|
||||
carddef.workflow = workflow
|
||||
carddef.fields = []
|
||||
carddef.store()
|
||||
|
||||
resp = app.get('/backoffice/workflows/1/')
|
||||
resp = resp.click(href='delete')
|
||||
assert 'This workflow is currently in use, you cannot remove it.' in resp.text
|
||||
|
||||
carddef.remove_self()
|
||||
|
||||
resp = app.get('/backoffice/workflows/1/')
|
||||
resp = resp.click(href='delete')
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/workflows/'
|
||||
|
|
|
@ -1758,8 +1758,9 @@ class WorkflowPage(Directory):
|
|||
|
||||
def delete(self):
|
||||
form = Form(enctype="multipart/form-data")
|
||||
for formdef in FormDef.select():
|
||||
if formdef.workflow_id == self.workflow.id:
|
||||
from itertools import chain
|
||||
for objdef in chain(FormDef.select(), CardDef.select()):
|
||||
if objdef.workflow_id == self.workflow.id:
|
||||
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
|
||||
"This workflow is currently in use, you cannot remove it.")))
|
||||
form.add_submit("cancel", _("Cancel"))
|
||||
|
|
Loading…
Reference in New Issue