Commit aaf66a77 authored by Julien Muchembled's avatar Julien Muchembled

Make load of local Document modules safer

Modules from local Document folders may override existing module.
If such local module can't be imported, the original module should be restored.
This is useful during upgrades.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36101 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1e967442
......@@ -920,15 +920,23 @@ def importLocalDocument(class_id, document_path = None):
path = document_path
path = os.path.join(path, "%s.py" % class_id)
module_path = 'Products.ERP5Type.Document.' + class_id
document_module = sys.modules.get(module_path)
# Import Document Class and Initialize it
f = open(path)
try:
document_module = imp.load_source(
'Products.ERP5Type.Document.%s' % class_id, path, f)
document_module = imp.load_source(module_path, path, f)
document_class = getattr(document_module, class_id)
document_constructor = DocumentConstructor(document_class)
document_constructor_name = "add%s" % class_id
document_constructor.__name__ = document_constructor_name
except Exception:
f.close()
if document_module is not None:
sys.modules[module_path] = document_module
raise
else:
f.close()
setattr(Products.ERP5Type.Document, class_id, document_module)
setattr(Products.ERP5Type.Document, document_constructor_name,
document_constructor)
......@@ -936,8 +944,6 @@ def importLocalDocument(class_id, document_path = None):
ModuleSecurityInfo('Products.ERP5Type.Document').declareProtected(
Permissions.AddPortalContent, document_constructor_name,)
InitializeClass(document_class)
finally:
f.close()
# Temp documents are created as standard classes with a different constructor
# which patches some methods are the instance level to prevent reindexing
......
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