Commit 5e4454e0 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_hal_json_style] Fix Base Domain document display

Base domain .getRelativeUrl method does not include portal_domains.
See https://lab.nexedi.com/nexedi/erp5/blob/c3f0585cc1ddb888d356b3395b947b90cb188356/product/ERP5/Document/Domain.py#L91
parent f402de4e
......@@ -536,7 +536,7 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None, k
}
result.update({
"url": traversed_document.getRelativeUrl(),
"url": getRealRelativeUrl(traversed_document),
"translated_portal_types": translated_portal_type,
"portal_types": portal_type_list,
"query": query,
......@@ -547,7 +547,7 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None, k
"search_view": url_template_dict['traverse_generator_action'] % {
"root_url": site_root.absolute_url(),
"script_id": script.id,
"relative_url": traversed_document.getRelativeUrl().replace("/", "%2F"),
"relative_url": getRealRelativeUrl(traversed_document).replace("/", "%2F"),
"view": "Base_viewRelatedObjectList",
"extra_param_json": urlsafe_b64encode(
json.dumps(ensureSerializable({
......@@ -671,7 +671,7 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None, k
list_method_custom = url_template_dict["custom_search_template"] % {
"root_url": site_root.absolute_url(),
"script_id": script.id,
"relative_url": traversed_document.getRelativeUrl().replace("/", "%2F"),
"relative_url": getRealRelativeUrl(traversed_document).replace("/", "%2F"),
"form_relative_url": "%s/%s" % (getFormRelativeUrl(form), field.id),
"list_method": list_method_name,
"default_param_json": urlsafe_b64encode(
......@@ -860,7 +860,7 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
response_dict['_actions'] = {
'put': {
"href": url_template_dict["form_action"] % {
"traversed_document_url": site_root.absolute_url() + "/" + traversed_document.getRelativeUrl(),
"traversed_document_url": site_root.absolute_url() + "/" + getRealRelativeUrl(traversed_document),
"action_id": action_to_call
},
"action": form.action,
......@@ -886,10 +886,10 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
response_dict['_links']['traversed_document'] = {
"href": default_document_uri_template % {
"root_url": site_root.absolute_url(),
"relative_url": traversed_document.getRelativeUrl(),
"relative_url": getRealRelativeUrl(traversed_document),
"script_id": script.id
},
"name": traversed_document.getRelativeUrl(),
"name": getRealRelativeUrl(traversed_document),
"title": traversed_document.getTitle()
}
......@@ -929,7 +929,7 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
"items": [(Base_translateString(y), url_template_dict['traverse_generator_action'] % {
"root_url": site_root.absolute_url(),
"script_id": script.id,
"relative_url": traversed_document.getRelativeUrl().replace("/", "%2F"),
"relative_url": getRealRelativeUrl(traversed_document).replace("/", "%2F"),
"view": "Base_viewRelatedObjectList",
"extra_param_json": urlsafe_b64encode(
json.dumps(ensureSerializable({
......@@ -952,7 +952,7 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
response_dict["proxy_form_id_list"]["default"] = url_template_dict['traverse_generator_action'] % {
"root_url": site_root.absolute_url(),
"script_id": script.id,
"relative_url": traversed_document.getRelativeUrl().replace("/", "%2F"),
"relative_url": getRealRelativeUrl(traversed_document).replace("/", "%2F"),
"view": "Base_viewRelatedObjectList",
"extra_param_json": urlsafe_b64encode(
json.dumps(ensureSerializable({
......@@ -1307,7 +1307,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
if view and (view != 'view') and (current_action.get('view_id', None) is None):
# XXX Allow to directly render a form
current_action['view_id'] = view
current_action['url'] = '%s/%s' % (traversed_document.getRelativeUrl(), view)
current_action['url'] = '%s/%s' % (getRealRelativeUrl(traversed_document), view)
current_action['params'] = {}
# If we have current action definition we are able to render embedded view
......@@ -1395,7 +1395,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
erp5_action_list[-1]['href'] = url_template_dict[url_template_key] % {
"root_url": site_root.absolute_url(),
"script_id": script.id, # this script (ERP5Document_getHateoas)
"relative_url": traversed_document.getRelativeUrl().replace("/", "%2F"),
"relative_url": getRealRelativeUrl(traversed_document).replace("/", "%2F"),
"view": erp5_action_list[-1]['name'],
"extra_param_json": urlsafe_b64encode(json.dumps(ensureSerializable(extra_param_json)))
}
......@@ -1821,7 +1821,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# JIO requires every item to have _links.self.href so it can construct
# links to the document. Here we have a object in RAM (which should
# never happen!) thus we provide temporary UID
brain_relative_url = "{}/{}".format(traversed_document.getRelativeUrl(), brain_uid)
brain_relative_url = "{}/{}".format(getRealRelativeUrl(traversed_document), brain_uid)
else:
brain_uid = brain.uid
brain_relative_url = getRealRelativeUrl(brain_document)
......
......@@ -745,6 +745,28 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_embedded']['_view']['listbox']['editable_column_list'], [['id', 'id']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['sort_column_list'], [])
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasDocument_base_domain_view(self):
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="traverse", relative_url='portal_domains/foo_domain', view="view")
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
self.assertEqual(result_dict['_embedded']['_view']['listbox']['list_method_template'],
'%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=search&relative_url=portal_domains%%2Ffoo_domain&form_relative_url=portal_skins/erp5_core/BaseDomain_view/listbox&list_method=objectValues&extra_param_json=eyJmb3JtX2lkIjogIkJhc2VEb21haW5fdmlldyJ9&default_param_json=eyJjaGVja2VkX3Blcm1pc3Npb24iOiAiVmlldyIsICJpZ25vcmVfdW5rbm93bl9jb2x1bW5zIjogdHJ1ZX0={&query,select_list*,limit*,group_by*,sort_on*,local_roles*,selection_domain*}' % self.portal.absolute_url())
self.assertEqual(result_dict['_embedded']['_view']['_links']['traversed_document']['href'], 'urn:jio:get:portal_domains/foo_domain')
self.assertEqual(result_dict['_embedded']['_view']['_links']['self']['href'], "%s/portal_domains/foo_domain/BaseDomain_view" %
self.portal.absolute_url())
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
......
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