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
Léo-Paul Géneau
erp5
Commits
01c8cca6
Commit
01c8cca6
authored
Apr 19, 2021
by
Boxiang Sun
Committed by
Romain Courteaud
May 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_hal_json_style: return 404 error if no view was found
Do not return wrong content type
parent
4460fe67
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+6
-2
bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py
...plateItem/portal_components/test.erp5.testHalJsonStyle.py
+13
-0
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
01c8cca6
...
@@ -1449,7 +1449,11 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -1449,7 +1449,11 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
view_context
=
traversed_document
view_context
=
traversed_document
else
:
else
:
view_context
=
traversed_document
.
restrictedTraverse
(
current_action
[
'other_context'
])
view_context
=
traversed_document
.
restrictedTraverse
(
current_action
[
'other_context'
])
view_instance
=
getattr
(
view_context
,
current_action
[
'view_id'
])
view_instance
=
getattr
(
view_context
,
current_action
[
'view_id'
],
None
)
if
view_instance
is
None
:
response
.
setStatus
(
404
)
return
""
if
(
view_instance
is
not
None
):
if
(
view_instance
is
not
None
):
embedded_dict
=
{
embedded_dict
=
{
'_links'
:
{
'_links'
:
{
...
@@ -2385,7 +2389,6 @@ if mode == 'url_generator':
...
@@ -2385,7 +2389,6 @@ if mode == 'url_generator':
context.Base_prepareCorsResponse(RESPONSE=response)
context.Base_prepareCorsResponse(RESPONSE=response)
response.setHeader('
Content
-
Type
', mime_type)
hateoas = calculateHateoas(relative_url=relative_url,
hateoas = calculateHateoas(relative_url=relative_url,
REQUEST=REQUEST, response=response, view=view, mode=mode,
REQUEST=REQUEST, response=response, view=view, mode=mode,
query=query, select_list=select_list, limit=limit, form=form,
query=query, select_list=select_list, limit=limit, form=form,
...
@@ -2396,4 +2399,5 @@ hateoas = calculateHateoas(relative_url=relative_url,
...
@@ -2396,4 +2399,5 @@ hateoas = calculateHateoas(relative_url=relative_url,
if hateoas == "":
if hateoas == "":
return hateoas
return hateoas
else:
else:
response.setHeader('
Content
-
Type
', mime_type)
return json.dumps(hateoas, indent=2)
return json.dumps(hateoas, indent=2)
bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py
View file @
01c8cca6
...
@@ -708,6 +708,19 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
...
@@ -708,6 +708,19 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
document
.
getRelativeUrl
()))
document
.
getRelativeUrl
()))
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'_actions'
][
'put'
][
'method'
],
'POST'
)
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'_actions'
][
'put'
][
'method'
],
'POST'
)
@
simulate
(
'Base_getRequestUrl'
,
'*args, **kwargs'
,
'return "http://example.org/bar"'
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
'return "application/hal+json"'
)
@
changeSkin
(
'Hal'
)
def
test_getHateoasDocument_non_existing_action
(
self
):
document
=
self
.
_makeDocument
()
fake_request
=
do_fake_request
(
"GET"
)
result
=
self
.
portal
.
web_site_module
.
hateoas
.
ERP5Document_getHateoas
(
REQUEST
=
fake_request
,
mode
=
"traverse"
,
relative_url
=
document
.
getRelativeUrl
(),
view
=
"not_existing_action"
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
status
,
404
)
self
.
assertEquals
(
fake_request
.
RESPONSE
.
getHeader
(
'Content-Type'
),
None
)
self
.
assertEqual
(
result
,
""
)
@
simulate
(
'Base_getRequestUrl'
,
'*args, **kwargs'
,
@
simulate
(
'Base_getRequestUrl'
,
'*args, **kwargs'
,
'return "http://example.org/bar"'
)
'return "http://example.org/bar"'
)
@
simulate
(
'Base_getRequestHeader'
,
'*args, **kwargs'
,
@
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