Commit 336393e8 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

erp5_api_style: jIOWebSection catches unauthorized Error and return proper error message

parent 904bdded
...@@ -28,11 +28,37 @@ ...@@ -28,11 +28,37 @@
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl import Unauthorized
from Acquisition import aq_inner from Acquisition import aq_inner
from erp5.component.document.WebSection import WebSection from erp5.component.document.WebSection import WebSection
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from zLOG import LOG, INFO
MARKER = [] MARKER = []
def convertTojIOAPICall(function):
"""
Wrap the method to create a log entry for each invocation to the zope logger
"""
def wrapper(self, *args, **kwd):
"""
Log the call, and the result of the call
"""
try:
retval = function(self, *args, **kwd)
except Unauthorized, e:
LOG('SlapTool', INFO, 'Converting Unauthorized to Unauthorized error mesage in JSON,',
error=True)
return self.ERP5Site_logApiErrorAndReturn(
error_code="403",
error_message=str(e),
error_name="Unauthorized"
)
return '%s' % retval
wrapper.__doc__ = function.__doc__
return wrapper
class jIOWebSection(WebSection): class jIOWebSection(WebSection):
""" """
This Web Section is a wrapper to jIO to pass content in the body This Web Section is a wrapper to jIO to pass content in the body
...@@ -57,6 +83,10 @@ class jIOWebSection(WebSection): ...@@ -57,6 +83,10 @@ class jIOWebSection(WebSection):
section = section.aq_parent section = section.aq_parent
return default return default
@convertTojIOAPICall
def _asjIOStyle(self, mode, text_content):
return self.ERP5Site_asjIOStyle(mode=mode, text_content=text_content)
security.declareProtected(Permissions.View, 'get') security.declareProtected(Permissions.View, 'get')
def get(self): #pylint:disable=arguments-differ def get(self): #pylint:disable=arguments-differ
""" """
...@@ -64,7 +94,7 @@ class jIOWebSection(WebSection): ...@@ -64,7 +94,7 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called __bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
""" """
# Register current web site physical path for later URL generation # Register current web site physical path for later URL generation
return self.ERP5Site_asjIOStyle(mode="get", text_content=self.REQUEST.get('BODY')) return self._asjIOStyle(mode="get", text_content=self.REQUEST.get('BODY'))
security.declareProtected(Permissions.View, 'post') security.declareProtected(Permissions.View, 'post')
def post(self): def post(self):
...@@ -73,7 +103,7 @@ class jIOWebSection(WebSection): ...@@ -73,7 +103,7 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called __bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
""" """
# Register current web site physical path for later URL generation # Register current web site physical path for later URL generation
return self.ERP5Site_asjIOStyle(mode="post", text_content=self.REQUEST.get('BODY')) return self._asjIOStyle(mode="post", text_content=self.REQUEST.get('BODY'))
security.declareProtected(Permissions.View, 'put') security.declareProtected(Permissions.View, 'put')
def put(self): def put(self):
...@@ -82,7 +112,7 @@ class jIOWebSection(WebSection): ...@@ -82,7 +112,7 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called __bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
""" """
# Register current web site physical path for later URL generation # Register current web site physical path for later URL generation
return self.ERP5Site_asjIOStyle(mode="put", text_content=self.REQUEST.get('BODY')) return self._asjIOStyle(mode="put", text_content=self.REQUEST.get('BODY'))
security.declareProtected(Permissions.View, 'allDocs') security.declareProtected(Permissions.View, 'allDocs')
def allDocs(self): def allDocs(self):
...@@ -91,4 +121,4 @@ class jIOWebSection(WebSection): ...@@ -91,4 +121,4 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called __bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
""" """
# Register current web site physical path for later URL generation # Register current web site physical path for later URL generation
return self.ERP5Site_asjIOStyle(mode="allDocs", text_content=self.REQUEST.get('BODY')) return self._asjIOStyle(mode="allDocs", text_content=self.REQUEST.get('BODY'))
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