Commit 8233b311 authored by Titouan Soulard's avatar Titouan Soulard

erp5_action_information_api: DROP add mock method for client

parent 2b85cab2
...@@ -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
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