From 7049e4780e387590746cbbc2fd4a1e5e51f7e0c8 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 31 May 2013 09:59:25 +0200 Subject: [PATCH] [gen] Improvement in the management of Unauthorized exceptions. --- gen/mixins/ToolMixin.py | 23 ++++++++++++++++------- gen/ui/appy.css | 1 + gen/ui/page.pt | 6 ++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/gen/mixins/ToolMixin.py b/gen/mixins/ToolMixin.py index 3999346..21bcfb8 100644 --- a/gen/mixins/ToolMixin.py +++ b/gen/mixins/ToolMixin.py @@ -1136,13 +1136,22 @@ class ToolMixin(BaseMixin): def manageError(self, error): '''Manages an error.''' tb = sys.exc_info() - from zExceptions.ExceptionFormatter import format_exception - htmlMessage = format_exception(tb[0], tb[1], tb[2], as_html=1) - textMessage = format_exception(tb[0], tb[1], tb[2], as_html=0) - self.log(''.join(textMessage).strip(), type='error') - return '' \ - '
An error occurred. %s' \ - '
' % '\n'.join(htmlMessage) + if error.type.__name__ == 'Unauthorized': + siteUrl = self.getSiteUrl() + htmlMessage = '' \ + '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) + textMessage = ''.join(textMessage).strip() + self.log(textMessage, type='error') + return '
%s
' % htmlMessage def getMainPages(self): '''Returns the main pages.''' diff --git a/gen/ui/appy.css b/gen/ui/appy.css index 08b570d..fc9a1e7 100644 --- a/gen/ui/appy.css +++ b/gen/ui/appy.css @@ -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 } diff --git a/gen/ui/page.pt b/gen/ui/page.pt index 860437d..d4ce6fa 100644 --- a/gen/ui/page.pt +++ b/gen/ui/page.pt @@ -118,8 +118,10 @@ - + + + +