forms: give access to workflow data when editing formdata (#49443)
This commit is contained in:
parent
45580748ae
commit
4a71b02611
|
@ -2620,6 +2620,59 @@ def test_backoffice_wfedit_and_data_source_with_user_info(pub):
|
|||
resp = resp.follow()
|
||||
|
||||
|
||||
def test_backoffice_wfedit_and_workflow_data(pub):
|
||||
user = create_user(pub)
|
||||
create_environment(pub)
|
||||
formdef = FormDef.get_by_urlname('form-title')
|
||||
|
||||
formdef.fields[2].data_source = {'type': 'json',
|
||||
'value': 'https://www.example.invalid/?test={% firstof some_workflow_data "XXX" %}'
|
||||
}
|
||||
formdef.store()
|
||||
|
||||
form_class = formdef.data_class()
|
||||
|
||||
number31 = [x for x in form_class.select() if x.data['1'] == 'FOO BAR 30'][0]
|
||||
|
||||
# attach a custom workflow
|
||||
workflow = Workflow(name='wfedit')
|
||||
st1 = workflow.add_status('Status1', number31.status.split('-')[1])
|
||||
|
||||
wfedit = EditableWorkflowStatusItem()
|
||||
wfedit.id = '_wfedit'
|
||||
wfedit.by = [user.roles[0]]
|
||||
st1.items.append(wfedit)
|
||||
wfedit.parent = st1
|
||||
workflow.store()
|
||||
|
||||
formdef.workflow_id = workflow.id
|
||||
formdef.store()
|
||||
|
||||
number31 = form_class().get(number31.id)
|
||||
number31.workflow_data = {'some_workflow_data': 'foobar'}
|
||||
number31.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
|
||||
with mock.patch('wcs.qommon.misc.urlopen') as urlopen:
|
||||
data = {'data': [{'id': 'A', 'text': 'hello'}, {'id': 'B', 'text': 'world'}]}
|
||||
|
||||
def side_effect(url, *args):
|
||||
assert '?test=foobar' in url
|
||||
return StringIO(json.dumps(data))
|
||||
|
||||
urlopen.side_effect = side_effect
|
||||
|
||||
resp = app.get('/backoffice/management/form-title/%s/' % number31.id)
|
||||
resp = resp.form.submit('button_wfedit')
|
||||
resp = resp.follow()
|
||||
assert urlopen.call_count == 1
|
||||
resp.form['f3'].value = 'A'
|
||||
resp = resp.form.submit('submit')
|
||||
assert urlopen.call_count == 2
|
||||
resp = resp.follow()
|
||||
|
||||
|
||||
def test_backoffice_wfedit_and_data_source_with_field_info(pub):
|
||||
user = create_user(pub)
|
||||
create_environment(pub)
|
||||
|
|
|
@ -622,6 +622,8 @@ class FormPage(Directory, FormTemplateMixin):
|
|||
# keep track of original formdata id so it can be used by
|
||||
# |exclude_self filter.
|
||||
formdata._edited_id = self.edited_data.id
|
||||
# keep workflow data as it may be used in conditions
|
||||
formdata.workflow_data = self.edited_data.workflow_data
|
||||
return formdata
|
||||
|
||||
if get_request().is_in_backoffice():
|
||||
|
|
Loading…
Reference in New Issue