Commit f7ac0348 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Titouan Soulard

erp5_api_style: jIOWebSection catches unauthorized Error and return proper error message

parent a18c39e3
......@@ -28,11 +28,37 @@
##############################################################################
from AccessControl import ClassSecurityInfo
from AccessControl import Unauthorized
from Acquisition import aq_inner
from erp5.component.document.WebSection import WebSection
from Products.ERP5Type import Permissions
from zLOG import LOG, INFO
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):
"""
This Web Section is a wrapper to jIO to pass content in the body
......@@ -57,6 +83,10 @@ class jIOWebSection(WebSection):
section = section.aq_parent
return default
@convertTojIOAPICall
def _asjIOStyle(self, mode, text_content):
return self.ERP5Site_asjIOStyle(mode=mode, text_content=text_content)
security.declareProtected(Permissions.View, 'get')
def get(self): #pylint:disable=arguments-differ
"""
......@@ -64,7 +94,7 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
"""
# 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')
def post(self):
......@@ -73,7 +103,7 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
"""
# 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')
def put(self):
......@@ -82,7 +112,7 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
"""
# 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')
def allDocs(self):
......@@ -91,4 +121,4 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
"""
# 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