Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Paul Graydon
erp5
Commits
59622856
Commit
59622856
authored
Mar 06, 2018
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_hal_json_style] Add support for selection domain query parameter
parent
62d31b8d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
8 deletions
+80
-8
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_restricted_style/ERP5Document_getHateoas.py
...erp5_hal_json_restricted_style/ERP5Document_getHateoas.py
+1
-0
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_restricted_style/ERP5Document_getHateoas.xml
...rp5_hal_json_restricted_style/ERP5Document_getHateoas.xml
+1
-1
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+18
-3
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.xml
...tal_skins/erp5_hal_json_style/ERP5Document_getHateoas.xml
+1
-1
bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py
...plateItem/portal_components/test.erp5.testHalJsonStyle.py
+59
-3
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_restricted_style/ERP5Document_getHateoas.py
View file @
59622856
...
...
@@ -23,5 +23,6 @@ return context.ERP5Document_getHateoas(
bulk_list
=
bulk_list
,
sort_on
=
sort_on
,
local_roles
=
local_roles
,
selection_domain
=
selection_domain
,
restricted
=
1
)
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_restricted_style/ERP5Document_getHateoas.xml
View file @
59622856
...
...
@@ -50,7 +50,7 @@
</item>
<item>
<key>
<string>
_params
</string>
</key>
<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>
<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
, selection_domain=None
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
...
...
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
59622856
...
...
@@ -368,19 +368,19 @@ url_template_dict = {
"traverse_template"
:
"%(root_url)s/%(script_id)s?mode=traverse"
+
\
"{&relative_url,view}"
,
"search_template"
:
"%(root_url)s/%(script_id)s?mode=search"
+
\
"{&query,select_list*,limit*,sort_on*,local_roles*}"
,
"{&query,select_list*,limit*,sort_on*,local_roles*
,selection_domain*
}"
,
"worklist_template"
:
"%(root_url)s/%(script_id)s?mode=worklist"
,
"custom_search_template"
:
"%(root_url)s/%(script_id)s?mode=search"
+
\
"&relative_url=%(relative_url)s"
\
"&form_relative_url=%(form_relative_url)s"
\
"&list_method=%(list_method)s"
\
"&default_param_json=%(default_param_json)s"
\
"{&query,select_list*,limit*,sort_on*,local_roles*}"
,
"{&query,select_list*,limit*,sort_on*,local_roles*
,selection_domain*
}"
,
"custom_search_template_no_editable"
:
"%(root_url)s/%(script_id)s?mode=search"
+
\
"&relative_url=%(relative_url)s"
\
"&list_method=%(list_method)s"
\
"&default_param_json=%(default_param_json)s"
\
"{&query,select_list*,limit*,sort_on*,local_roles*}"
,
"{&query,select_list*,limit*,sort_on*,local_roles*
,selection_domain*
}"
,
"new_content_action"
:
"%(root_url)s/%(script_id)s?mode=newContent"
,
"bulk_action"
:
"%(root_url)s/%(script_id)s?mode=bulk"
,
# XXX View is set by default to empty
...
...
@@ -1491,6 +1491,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# select_list: ['int_index', 'id', 'title', ...] (column names to select)
# limit: [15, 16] (begin_index, num_records)
# local_roles: TODO
# selection_domain: JSON string: {region: 'foo/bar'}
#
# Default Param JSON contains
# portal_type: list of Portal Types to include (singular form matches the
...
...
@@ -1539,6 +1540,19 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
if
query
:
catalog_kw
[
"full_text"
]
=
query
if
selection_domain
is
not
None
:
selection_domain_dict
=
ensureDeserialized
(
byteify
(
json
.
loads
(
selection_domain
)))
category_tool
=
portal
.
portal_categories
domain_tool
=
portal
.
portal_domains
for
domain_root_id
in
selection_domain_dict
:
domain_root
=
category_tool
.
restrictedTraverse
(
domain_root_id
,
None
)
if
domain_root
is
None
:
selection_domain_dict
[
domain_root_id
]
=
domain_tool
.
getDomainByPath
(
'%s/%s'
%
(
domain_root_id
,
selection_domain_dict
[
domain_root_id
]))
else
:
selection_domain_dict
[
domain_root_id
]
=
domain_root
.
restrictedTraverse
(
selection_domain_dict
[
domain_root_id
])
catalog_kw
[
"selection_domain"
]
=
selection_domain_dict
if
sort_on
is
not
None
:
def
parseSortOn
(
raw_string
):
"""Turn JSON serialized array into a tuple (col_name, order)."""
...
...
@@ -1632,6 +1646,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
result_dict
.
update
({
'_query'
:
query
,
'_local_roles'
:
local_roles
,
'_selection_domain'
:
selection_domain
,
'_limit'
:
limit
,
'_select_list'
:
select_list
,
'_embedded'
:
{}
...
...
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.xml
View file @
59622856
...
...
@@ -56,7 +56,7 @@
</item>
<item>
<key>
<string>
_params
</string>
</key>
<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=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, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None
, selection_domain=None
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
...
...
bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py
View file @
59622856
...
...
@@ -414,7 +414,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*,local_roles*}"
%
self
.
portal
.
absolute_url
())
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=search{&query,select_list*,limit*,sort_on*,local_roles*
,selection_domain*
}"
%
self
.
portal
.
absolute_url
())
self
.
assertEqual
(
result_dict
[
'_links'
][
'raw_search'
][
'templated'
],
True
)
self
.
assertEqual
(
result_dict
[
'_links'
][
'raw_search'
][
'name'
],
"Raw Search"
)
...
...
@@ -629,7 +629,7 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'listbox'
][
'editable_column_list'
],
[[
'id'
,
'ID'
],
[
'title'
,
'Title'
],
[
'quantity'
,
'quantity'
],
[
'start_date'
,
'Date'
]])
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'listbox'
][
'sort_column_list'
],
[[
'id'
,
'ID'
],
[
'title'
,
'Title'
],
[
'quantity'
,
'Quantity'
],
[
'start_date'
,
'Date'
]])
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'listbox'
][
'list_method_template'
],
'%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=search&relative_url=foo_module%%2F%s&form_relative_url=portal_skins/erp5_ui_test/Foo_view/listbox&list_method=objectValues&default_param_json=eyJwb3J0YWxfdHlwZSI6IFsiRm9vIExpbmUiXSwgImlnbm9yZV91bmtub3duX2NvbHVtbnMiOiB0cnVlfQ=={&query,select_list*,limit*,sort_on*,local_roles*}'
%
(
self
.
portal
.
absolute_url
(),
document
.
getId
()))
'%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=search&relative_url=foo_module%%2F%s&form_relative_url=portal_skins/erp5_ui_test/Foo_view/listbox&list_method=objectValues&default_param_json=eyJwb3J0YWxfdHlwZSI6IFsiRm9vIExpbmUiXSwgImlnbm9yZV91bmtub3duX2NvbHVtbnMiOiB0cnVlfQ=={&query,select_list*,limit*,sort_on*,local_roles*
,selection_domain*
}'
%
(
self
.
portal
.
absolute_url
(),
document
.
getId
()))
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'_links'
][
'traversed_document'
][
'href'
],
'urn:jio:get:%s'
%
document
.
getRelativeUrl
())
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'_links'
][
'traversed_document'
][
'name'
],
document
.
getRelativeUrl
())
...
...
@@ -884,7 +884,7 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['
_embedded
']['
_view
']['
report_section_list
'][1]['
listbox
']['
editable_column_list
'], [['
time
', '
Time
'], ['
comment
', '
Comment
'], ['
error_message
', '
Error
Message
']])
self.assertEqual(result_dict['
_embedded
']['
_view
']['
report_section_list
'][1]['
listbox
']['
sort_column_list
'], [])
self.assertEqual(result_dict['
_embedded
']['
_view
']['
report_section_list
'][1]['
listbox
']['
list_method_template
'],
'
%
s
/
web_site_module
/
hateoas
/
ERP5Document_getHateoas
?
mode
=
search
&
relative_url
=
foo_module
%%
2
F
%
s
&
form_relative_url
=
portal_skins
/
erp5_core
/
Base_viewWorkflowHistory
/
listbox
&
list_method
=
Base_getWorkflowHistoryItemList
&
default_param_json
=
eyJ3b3JrZmxvd19pZCI6ICJmb29fd29ya2Zsb3ciLCAiY2hlY2tlZF9wZXJtaXNzaW9uIjogIlZpZXciLCAid29ya2Zsb3dfdGl0bGUiOiAiRm9vIFdvcmtmbG93IiwgImlnbm9yZV91bmtub3duX2NvbHVtbnMiOiB0cnVlfQ
==
{
&
query
,
select_list
*
,
limit
*
,
sort_on
*
,
local_roles
*
}
' % (self.portal.absolute_url(), document.getId()))
'
%
s
/
web_site_module
/
hateoas
/
ERP5Document_getHateoas
?
mode
=
search
&
relative_url
=
foo_module
%%
2
F
%
s
&
form_relative_url
=
portal_skins
/
erp5_core
/
Base_viewWorkflowHistory
/
listbox
&
list_method
=
Base_getWorkflowHistoryItemList
&
default_param_json
=
eyJ3b3JrZmxvd19pZCI6ICJmb29fd29ya2Zsb3ciLCAiY2hlY2tlZF9wZXJtaXNzaW9uIjogIlZpZXciLCAid29ya2Zsb3dfdGl0bGUiOiAiRm9vIFdvcmtmbG93IiwgImlnbm9yZV91bmtub3duX2NvbHVtbnMiOiB0cnVlfQ
==
{
&
query
,
select_list
*
,
limit
*
,
sort_on
*
,
local_roles
*
,
selection_domain
*
}
' % (self.portal.absolute_url(), document.getId()))
@simulate('
Base_getRequestUrl
', '
*
args
,
**
kwargs
',
...
...
@@ -1085,6 +1085,62 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
# No count if not in the listbox context currently
self.assertEqual(result_dict['
_embedded
'].get('
count
', None), None)
@simulate('
Base_getRequestUrl
', '
*
args
,
**
kwargs
',
'
return
"http://example.org/bar"')
@simulate('
Base_getRequestHeader
', '
*
args
,
**
kwargs
',
'
return
"application/hal+json"')
@changeSkin('
Hal
')
def test_getHateoas_selection_domain_category_param(self):
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="search", selection_domain=json.dumps({'
foo_category
': '
a
/
a2
'}))
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
'], None)
self.assertEqual(result_dict['
_selection_domain
'], '
{
"foo_category"
:
"a/a2"
}
')
self.assertEqual(result_dict['
_select_list
'], [])
self.assertEqual(len(result_dict['
_embedded
']['
contents
']), 1)
self.assertEqual(result_dict['
_embedded
']['
contents
'][0]["_links"]["self"]["href"], "urn:jio:get:portal_categories/foo_category/a/a2")
# No count if not in the listbox context currently
self.assertEqual(result_dict['
_embedded
'].get('
count
', None), None)
@simulate('
Base_getRequestUrl
', '
*
args
,
**
kwargs
',
'
return
"http://example.org/bar"')
@simulate('
Base_getRequestHeader
', '
*
args
,
**
kwargs
',
'
return
"application/hal+json"')
@changeSkin('
Hal
')
def test_getHateoas_selection_domain_domain_param(self):
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="search", selection_domain=json.dumps({'
foo_domain
': '
a
/
a1
'}))
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
'], None)
self.assertEqual(result_dict['
_selection_domain
'], '
{
"foo_domain"
:
"a/a1"
}
')
self.assertEqual(result_dict['
_select_list
'], [])
self.assertEqual(len(result_dict['
_embedded
']['
contents
']), 1)
self.assertEqual(result_dict['
_embedded
']['
contents
'][0]["_links"]["self"]["href"], "urn:jio:get:portal_categories/foo_category/a/a1")
# No count if not in the listbox context currently
self.assertEqual(result_dict['
_embedded
'].get('
count
', None), None)
@simulate('
Base_getRequestUrl
', '
*
args
,
**
kwargs
',
'
return
"http://example.org/bar"')
@simulate('
Base_getRequestHeader
', '
*
args
,
**
kwargs
',
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment