Commit 02d0d636 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_hal_json_style] Add support for local roles parameter

local_roles can not be expressed as a catalog query and should be provided as an explicit value
parent 50f1c236
......@@ -74,13 +74,14 @@ return context.ERP5Document_getHateoas(\n
form_relative_url=form_relative_url,\n
bulk_list=bulk_list,\n
sort_on=sort_on,\n
local_roles=local_roles,\n
restricted=1\n
)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None</string> </value>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -75,18 +75,18 @@ url_template_dict = {\n
"traverse_template": "%(root_url)s/%(script_id)s?mode=traverse" + \\\n
"{&relative_url,view}",\n
"search_template": "%(root_url)s/%(script_id)s?mode=search" + \\\n
"{&query,select_list*,limit*,sort_on*}",\n
"{&query,select_list*,limit*,sort_on*,local_roles*}",\n
"custom_search_template": "%(root_url)s/%(script_id)s?mode=search" + \\\n
"&relative_url=%(relative_url)s" \\\n
"&form_relative_url=%(form_relative_url)s" \\\n
"&list_method=%(list_method)s" \\\n
"&default_param_json=%(default_param_json)s" \\\n
"{&query,select_list*,limit*,sort_on*}",\n
"{&query,select_list*,limit*,sort_on*,local_roles*}",\n
"custom_search_template_no_editable": "%(root_url)s/%(script_id)s?mode=search" + \\\n
"&relative_url=%(relative_url)s" \\\n
"&list_method=%(list_method)s" \\\n
"&default_param_json=%(default_param_json)s" \\\n
"{&query,select_list*,limit*,sort_on*}",\n
"{&query,select_list*,limit*,sort_on*,local_roles*}",\n
"new_content_action": "%(root_url)s/%(script_id)s?mode=newContent",\n
"bulk_action": "%(root_url)s/%(script_id)s?mode=bulk",\n
# XXX View is set by default to empty\n
......@@ -927,9 +927,9 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
tmp_sort_on += (tuple([x for x in grain.split(",")]),)\n
\n
if query:\n
sql_list = callable_list_method(full_text=query, limit=limit, sort_on=tmp_sort_on, **catalog_kw)\n
sql_list = callable_list_method(full_text=query, limit=limit, sort_on=tmp_sort_on, local_roles=local_roles, **catalog_kw)\n
else:\n
sql_list = callable_list_method(limit=limit, sort_on=tmp_sort_on, **catalog_kw)\n
sql_list = callable_list_method(limit=limit, sort_on=tmp_sort_on, local_roles=local_roles, **catalog_kw)\n
\n
result_list = []\n
\n
......@@ -1016,6 +1016,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
result_dict[\'_embedded\'] = {"contents": result_list}\n
\n
result_dict[\'_query\'] = query\n
result_dict[\'_local_roles\'] = local_roles\n
result_dict[\'_limit\'] = limit\n
result_dict[\'_select_list\'] = select_list\n
\n
......@@ -1086,7 +1087,7 @@ else:\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=()</string> </value>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=()</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -348,7 +348,7 @@ class TestERP5Document_getHateoas_mode_root(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_links']['type']['name'], document.getPortalType())
self.assertEqual(result_dict['_links']['raw_search']['href'],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=search{&query,select_list*,limit*,sort_on*}" % self.portal.absolute_url())
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=search{&query,select_list*,limit*,sort_on*,local_roles*}" % self.portal.absolute_url())
self.assertEqual(result_dict['_links']['raw_search']['templated'], True)
self.assertEqual(result_dict['_links']['raw_search']['name'], "Raw Search")
......@@ -612,6 +612,7 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_debug'], "search")
self.assertEqual(result_dict['_limit'], 10)
self.assertEqual(result_dict['_query'], None)
self.assertEqual(result_dict['_local_roles'], None)
self.assertEqual(result_dict['_select_list'], [])
self.assertEqual(len(result_dict['_embedded']['contents']), 10)
......@@ -635,6 +636,7 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_debug'], "search")
self.assertEqual(result_dict['_limit'], 1)
self.assertEqual(result_dict['_query'], None)
self.assertEqual(result_dict['_local_roles'], None)
self.assertEqual(result_dict['_select_list'], [])
self.assertEqual(len(result_dict['_embedded']['contents']), 1)
......@@ -661,6 +663,7 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_debug'], "search")
self.assertEqual(result_dict['_limit'], 10)
self.assertEqual(result_dict['_query'], None)
self.assertEqual(result_dict['_local_roles'], None)
self.assertEqual(result_dict['_select_list'], ["id", "relative_url"])
self.assertEqual(len(result_dict['_embedded']['contents']), 10)
......@@ -686,10 +689,33 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_debug'], "search")
self.assertEqual(result_dict['_limit'], 10)
self.assertEqual(result_dict['_query'], "ANIMPOSSIBLECOUSCOUSVALUEFOOTOFINDINDATA")
self.assertEqual(result_dict['_local_roles'], None)
self.assertEqual(result_dict['_select_list'], [])
self.assertEqual(len(result_dict['_embedded']['contents']), 0)
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoas_local_roles_param(self):
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="search", local_roles=["Assignor", "Assignee"])
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['_links']['self'], {"href": "http://example.org/bar"})
self.assertEqual(result_dict['_debug'], "search")
self.assertEqual(result_dict['_limit'], 10)
self.assertEqual(result_dict['_query'], None)
self.assertEqual(result_dict['_local_roles'], ["Assignor", "Assignee"])
self.assertEqual(result_dict['_select_list'], [])
self.assertEqual(len(result_dict['_embedded']['contents']), 0)
class TestERP5Document_getHateoas_mode_bulk(ERP5HALJSONStyleSkinsMixin):
......
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