Commit 4e9ebe02 authored by Romain Courteaud's avatar Romain Courteaud

Catch Unauthorized exception which may be raised by index_html (through...

Catch Unauthorized exception which may be raised by index_html (through checkConversionFormatPermission script), and return a nicer message to the user.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21269 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b47b6eec
...@@ -73,7 +73,14 @@ output (a file in desired format).\n ...@@ -73,7 +73,14 @@ output (a file in desired format).\n
request = context.REQUEST\n request = context.REQUEST\n
response = request.RESPONSE\n response = request.RESPONSE\n
\n \n
data = context.index_html(request, response, format=format, force=force)\n from zExceptions import Unauthorized\n
\n
try:\n
data = context.index_html(request, response, format=format, force=force)\n
except Unauthorized:\n
msg = context.Base_translateString("You don\'t have enough permission for converting this document.")\n
return context.Base_redirect(keep_items=dict(portal_status_message=msg))\n
\n
typ = response.headers.get(\'content-type\')\n typ = response.headers.get(\'content-type\')\n
\n \n
if not filename:\n if not filename:\n
...@@ -143,7 +150,11 @@ return data\n ...@@ -143,7 +150,11 @@ return data\n
<string>context</string> <string>context</string>
<string>request</string> <string>request</string>
<string>response</string> <string>response</string>
<string>zExceptions</string>
<string>Unauthorized</string>
<string>data</string> <string>data</string>
<string>msg</string>
<string>dict</string>
<string>typ</string> <string>typ</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>_inplacevar_</string> <string>_inplacevar_</string>
......
10 11
\ No newline at end of file \ No newline at end of file
...@@ -3,11 +3,8 @@ ...@@ -3,11 +3,8 @@
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<tuple> <tuple>
<tuple> <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<string>Products.PythonScripts.PythonScript</string> <tuple/>
<string>PythonScript</string>
</tuple>
<none/>
</tuple> </tuple>
</pickle> </pickle>
<pickle> <pickle>
...@@ -71,6 +68,14 @@ ...@@ -71,6 +68,14 @@
<value> <string>request = container.REQUEST\n <value> <string>request = container.REQUEST\n
response = request.RESPONSE\n response = request.RESPONSE\n
\n \n
from zExceptions import Unauthorized\n
\n
try:\n
result = context.index_html(request, response)\n
except Unauthorized:\n
msg = context.Base_translateString("You don\'t have enough permission for converting this document.")\n
return context.Base_redirect(keep_items=dict(portal_status_message=msg))\n
\n
if hasattr(context,\'getContentType\'):\n if hasattr(context,\'getContentType\'):\n
response.setHeader(\'Content-type\', context.getContentType())\n response.setHeader(\'Content-type\', context.getContentType())\n
else:\n else:\n
...@@ -78,7 +83,8 @@ else:\n ...@@ -78,7 +83,8 @@ else:\n
\n \n
file_name = context.getSourceReference() or context.getTitle() or context.getId()\n file_name = context.getSourceReference() or context.getTitle() or context.getId()\n
response.setHeader(\'Content-disposition\', \'attachment; filename="%s"\' % file_name)\n response.setHeader(\'Content-disposition\', \'attachment; filename="%s"\' % file_name)\n
return context.index_html(request, response)\n \n
return result\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -125,8 +131,13 @@ return context.index_html(request, response)\n ...@@ -125,8 +131,13 @@ return context.index_html(request, response)\n
<string>container</string> <string>container</string>
<string>request</string> <string>request</string>
<string>response</string> <string>response</string>
<string>hasattr</string> <string>zExceptions</string>
<string>Unauthorized</string>
<string>context</string> <string>context</string>
<string>result</string>
<string>msg</string>
<string>dict</string>
<string>hasattr</string>
<string>file_name</string> <string>file_name</string>
</tuple> </tuple>
</value> </value>
......
826 827
\ No newline at end of file \ No newline at end of file
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