Commit db839e95 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[hal_json] Fix invalid workflow dialog returning HTML instead of JSON

/reviewed-on nexedi/erp5!586
parent 9f329a70
...@@ -48,19 +48,11 @@ if dialog_method == 'Base_configureSortOn': ...@@ -48,19 +48,11 @@ if dialog_method == 'Base_configureSortOn':
selection_name=kw['selection_name'], selection_name=kw['selection_name'],
field_sort_on=kw['field_sort_on'], field_sort_on=kw['field_sort_on'],
field_sort_order=kw['field_sort_order']) field_sort_order=kw['field_sort_order'])
# Exceptions for Base_edit
# if dialog_method == 'Base_edit':
# return context.Base_edit(form_id=kw['form_id'],
# dialog_id=dialog_id,
# selection_name=kw['selection_name'])
# Exceptions for Workflow # Exceptions for Workflow
if dialog_method == 'Workflow_statusModify': if dialog_method == 'Workflow_statusModify':
value = context.Workflow_statusModify(form_id=kw['form_id'], return context.Workflow_statusModify(form_id=kw['form_id'],
dialog_id=dialog_id) dialog_id=dialog_id)
# XXX: This test is related to erp5_web and should not be present in configuration where it is not installed.
#if not(getattr(context.REQUEST, 'ignore_layout', 0)) and context.getApplicableLayout() :
# context.REQUEST.RESPONSE.redirect(context.WebSite_getDocumentPhysicalPath())
return value
# Exception for edit relation # Exception for edit relation
if dialog_method == 'Base_editRelation': if dialog_method == 'Base_editRelation':
return context.Base_editRelation(form_id=kw['form_id'], return context.Base_editRelation(form_id=kw['form_id'],
...@@ -99,7 +91,6 @@ if not hasattr(form, 'validate_all_to_request'): ...@@ -99,7 +91,6 @@ if not hasattr(form, 'validate_all_to_request'):
try: try:
# It is necessary to force editable_mode before validating # It is necessary to force editable_mode before validating
# data. Otherwise, field appears as non editable. # data. Otherwise, field appears as non editable.
# This is the pending of form_dialog.
editable_mode = request.get('editable_mode', 1) editable_mode = request.get('editable_mode', 1)
request.set('editable_mode', 1) request.set('editable_mode', 1)
form.validate_all_to_request(request) form.validate_all_to_request(request)
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testFormDialogWorkflowError</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test Workflow Transition with Invalid Form</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test Workflow Transition with Invalid Form</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/PTZuite_CommonTemplate/macros/init" />
<tr>
<td>open</td>
<td>${base_url}/web_site_module/renderjs_runner/#/foo_module/1?editable=1</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//a[text()='Actions']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//a[text()='Actions']</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//a[@data-i18n='Custom Required Dialog']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//a[@data-i18n='Custom Required Dialog']</td>
<td></td>
</tr>
<!-- Wait for gadget to be loaded -->
<tr>
<td>waitForElementPresent</td>
<td>//input[@name='field_your_custom_workflow_variable']</td>
<td></td>
</tr>
<!-- Do not fill anything to provoke form validation failure -->
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_dialog" />
<tr><td>waitForElementPresent</td>
<td>//div[@data-gadget-scope="field_your_custom_workflow_variable"]/div/span</td><td></td></tr>
<tr><td>assertText</td>
<td>//div[@data-gadget-scope="field_your_custom_workflow_variable"]/div/span</td>
<td>Input is required but no input given.</td></tr>
<tr><td>type</td>
<td>//textarea[@name='field_your_comment']</td>
<td>QWERTY</td></tr>
<tr><td>type</td>
<td>//input[@name='field_your_custom_workflow_variable']</td>
<td>YTREWQ</td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_dialog" />
<!-- Wait for the notification to appear. We cannot use verifyText because the button
is there all the time. It gets text assigned and is shown asynchronously later. -->
<tal:block tal:define="notification_configuration python: {'class': 'success',
'text': 'Status changed.'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_notification" />
</tal:block>
</tbody></table>
</body>
</html>
\ No newline at end of file
...@@ -4,7 +4,7 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed ...@@ -4,7 +4,7 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
from Products.ERP5Type.Log import log from Products.ERP5Type.Log import log
portal = context.getPortalObject() portal = context.getPortalObject()
request=context.REQUEST request = kw.get("REQUEST", None) or context.REQUEST
form = getattr(context, dialog_id) form = getattr(context, dialog_id)
...@@ -21,7 +21,7 @@ except FormValidationError, validation_errors: ...@@ -21,7 +21,7 @@ except FormValidationError, validation_errors:
# Pack errors into the request # Pack errors into the request
field_errors = form.ErrorFields(validation_errors) field_errors = form.ErrorFields(validation_errors)
request.set('field_errors', field_errors) request.set('field_errors', field_errors)
return form(request) return context.Base_renderForm(dialog_id)
# XXX: this is a duplication from form validation code in Base_callDialogMethod # XXX: this is a duplication from form validation code in Base_callDialogMethod
# Correct fix is to factorise this script with Base_callDialogMethod, not to # Correct fix is to factorise this script with Base_callDialogMethod, not to
...@@ -81,7 +81,7 @@ except ValidationFailed, error_message: ...@@ -81,7 +81,7 @@ except ValidationFailed, error_message:
# that would become an error. # that would become an error.
log("Status message has been truncated") log("Status message has been truncated")
message = "%s ..." % message[:(2000 - 4)] message = "%s ..." % message[:(2000 - 4)]
except WorkflowException, error_message: except WorkflowException as error_message:
if str(error_message) == "No workflow provides the '${action_id}' action.": if str(error_message) == "No workflow provides the '${action_id}' action.":
message = translateString("Workflow state may have been updated by other user. Please try again.") message = translateString("Workflow state may have been updated by other user. Please try again.")
return context.Base_redirect(form_id, keep_items={'portal_status_message': message}, **kw) return context.Base_redirect(form_id, keep_items={'portal_status_message': message}, **kw)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment