[gen] Improvement in the management of Unauthorized exceptions.
This commit is contained in:
parent
0c50fe188a
commit
7049e4780e
|
@ -1136,13 +1136,22 @@ class ToolMixin(BaseMixin):
|
|||
def manageError(self, error):
|
||||
'''Manages an error.'''
|
||||
tb = sys.exc_info()
|
||||
if error.type.__name__ == 'Unauthorized':
|
||||
siteUrl = self.getSiteUrl()
|
||||
htmlMessage = '<a href="%s"><img src="%s/ui/home.gif"/></a>' \
|
||||
'You are not allowed to access this page.' % \
|
||||
(siteUrl, siteUrl)
|
||||
userId = self.appy().user.getId() or 'system|anon'
|
||||
textMessage = 'Unauthorized for %s @%s.' % \
|
||||
(userId, self.REQUEST.get('PATH_INFO'))
|
||||
else:
|
||||
from zExceptions.ExceptionFormatter import format_exception
|
||||
htmlMessage = format_exception(tb[0], tb[1], tb[2], as_html=1)
|
||||
htmlMessage = '\n'.join(htmlMessage)
|
||||
textMessage = format_exception(tb[0], tb[1], tb[2], as_html=0)
|
||||
self.log(''.join(textMessage).strip(), type='error')
|
||||
return '<table class="main" align="center" cellpadding="0"><tr>' \
|
||||
'<td style="padding: 1em 1em 1em 1em">An error occurred. %s' \
|
||||
'</td></tr></table>' % '\n'.join(htmlMessage)
|
||||
textMessage = ''.join(textMessage).strip()
|
||||
self.log(textMessage, type='error')
|
||||
return '<div class="error" align="center">%s</div>' % htmlMessage
|
||||
|
||||
def getMainPages(self):
|
||||
'''Returns the main pages.'''
|
||||
|
|
|
@ -146,3 +146,4 @@ img { border: 0; vertical-align: middle }
|
|||
.homeTable td { padding: 10px 5px 10px 10px }
|
||||
.homeTable th { padding-top: 5px; font-size: 105% }
|
||||
.first { margin-top: 0px }
|
||||
.error { margin: 5px }
|
||||
|
|
|
@ -118,8 +118,10 @@
|
|||
</td>
|
||||
<td tal:condition="not: isDataChange"
|
||||
tal:content="python: _(contextObj.getWorkflowLabel(event['action']))"/>
|
||||
<td tal:define="actorId python:event.get('actor')"
|
||||
tal:content="python: tool.getUserName(actorId)"/>
|
||||
<td tal:define="actorId python:event.get('actor')">
|
||||
<span tal:condition="not: actorId" tal:replace="python: '?'"/>
|
||||
<span tal:condition="actorId" tal:content="python: tool.getUserName(actorId)"></span>
|
||||
</td>
|
||||
<td tal:content="python: tool.formatDate(event['time'], withHour=True)"/>
|
||||
<td tal:condition="not: isDataChange">
|
||||
<tal:c condition="rhComments"
|
||||
|
|
Loading…
Reference in a new issue