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
Titouan Soulard
erp5
Commits
8233b311
Commit
8233b311
authored
1 month ago
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_action_information_api: DROP add mock method for client
parent
2b85cab2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
11 deletions
+43
-11
bt5/erp5_action_information_api/DocumentTemplateItem/portal_components/document.erp5.ActionInformationAPIWebSection.py
...omponents/document.erp5.ActionInformationAPIWebSection.py
+43
-11
No files found.
bt5/erp5_action_information_api/DocumentTemplateItem/portal_components/document.erp5.ActionInformationAPIWebSection.py
View file @
8233b311
...
@@ -28,24 +28,28 @@
...
@@ -28,24 +28,28 @@
import
json
import
json
from
AccessControl
import
ClassSecurityInfo
from
AccessControl
import
ClassSecurityInfo
from
zExceptions
import
NotFound
from
zExceptions
import
BadRequest
,
NotFound
from
Products.ERP5Type
import
Permissions
,
PropertySheet
from
Products.ERP5Type
import
Permissions
,
PropertySheet
from
erp5.component.mixin.DocumentExtensibleTraversableMixin
import
DocumentExtensibleTraversableMixin
from
erp5.component.mixin.DocumentExtensibleTraversableMixin
import
DocumentExtensibleTraversableMixin
from
erp5.component.document.WebSection
import
WebSection
from
erp5.component.document.WebSection
import
WebSection
def
_handleJSONError
(
RESPONSE
,
exception
):
RESPONSE
.
setStatus
(
exception
.
status_code
,
lock
=
True
)
RESPONSE
.
setBody
(
exception
.
json
,
lock
=
True
)
class
ActionInformationAPIException
(
Exception
):
class
ActionInformationAPIException
(
Exception
):
"""
JSON error object, to avoid ERP5 default error pages.
Publishable but non-Persistent and without Acquisition.
"""
def
__init__
(
self
,
message
,
json_dict
):
def
__init__
(
self
,
message
,
json_dict
):
super
(
ActionInformationAPIException
,
self
).
__init__
(
message
)
super
(
ActionInformationAPIException
,
self
).
__init__
(
message
)
self
.
status_code
=
json_dict
[
"status_code"
]
self
.
status_code
=
json_dict
[
"status_code"
]
self
.
json
=
json
.
dumps
(
json_dict
)
self
.
json
=
json
.
dumps
(
json_dict
)
def
__call__
(
self
):
return
self
.
json
class
ActionInformationAPIWebSection
(
WebSection
):
class
ActionInformationAPIWebSection
(
WebSection
):
"""
"""
Type of Web Section defining an API.
Type of Web Section defining an API.
...
@@ -65,6 +69,38 @@ class ActionInformationAPIWebSection(WebSection):
...
@@ -65,6 +69,38 @@ class ActionInformationAPIWebSection(WebSection):
,
PropertySheet
.
Arrow
,
PropertySheet
.
Arrow
)
)
# XXX: this is a temporary implementation for partners to have something to play with
security
.
declarePublic
(
"allDocs"
)
def
allDocs
(
self
,
REQUEST
):
"""
Implementation of allDocs (ie. search) method.
"""
body
=
REQUEST
.
get
(
"BODY"
)
try
:
# XXX: router should not be hardcoded
method_id
=
self
.
ERP5Site_portalTypeRouter
(
body
)
except
BadRequest
as
e
:
error_message
=
str
(
e
)
error_context
=
{
"status_code"
:
400
,
"error_message"
:
error_message
,
"error_name"
:
"BadRequest"
,
}
# XXX: return does not seem right...
# XXX: why should we call here?
return
ActionInformationAPIException
(
error_message
,
error_context
)()
method
=
getattr
(
self
,
method_id
,
None
)
if
method
is
None
:
error_context
=
{
"status_code"
:
500
,
"error_name"
:
"InternalError"
,
}
return
ActionInformationAPIException
(
"No matching method found"
,
error_context
)()
return
method
(
body
)
security
.
declareProtected
(
Permissions
.
View
,
"__bobo_traverse__"
)
security
.
declareProtected
(
Permissions
.
View
,
"__bobo_traverse__"
)
def
__bobo_traverse__
(
self
,
REQUEST
,
name
):
def
__bobo_traverse__
(
self
,
REQUEST
,
name
):
mime_type
=
self
.
getMimeType
()
mime_type
=
self
.
getMimeType
()
...
@@ -83,12 +119,8 @@ class ActionInformationAPIWebSection(WebSection):
...
@@ -83,12 +119,8 @@ class ActionInformationAPIWebSection(WebSection):
"status_code"
:
404
,
"status_code"
:
404
,
"error_message"
:
error_message
,
"error_message"
:
error_message
,
"error_name"
:
"NotFound"
,
"error_name"
:
"NotFound"
,
"text_content"
:
REQUEST
.
getBody
()
}
}
error
=
ActionInformationAPIException
(
error_message
,
error_context
)
# XXX: return does not seem right...
# Ensure to return JSON error and re-raise
return
ActionInformationAPIException
(
error_message
,
error_context
)
_handleJSONError
(
REQUEST
.
response
,
error
)
#raise
return
"{}"
return
document
return
document
This diff is collapsed.
Click to expand it.
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