From 528cca9aa0772201a1fb742a00315c8c2ee3ba28 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Sun, 25 Aug 2013 08:59:53 +0200 Subject: [PATCH] [gen] Bugfix in gen.utils.createObject. --- doc/version.txt | 2 +- gen/utils.py | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/version.txt b/doc/version.txt index 7ada0d3..ac39a10 100644 --- a/doc/version.txt +++ b/doc/version.txt @@ -1 +1 @@ -0.8.5 +0.9.0 diff --git a/gen/utils.py b/gen/utils.py index f3476c6..e1671d3 100644 --- a/gen/utils.py +++ b/gen/utils.py @@ -11,17 +11,25 @@ def createObject(folder, id, className, appName, wf=True, noSecurity=False): p_wf=False.''' exec 'from Products.%s.%s import %s as ZopeClass' % \ (appName, className, className) - # Get the tool. Depends on whether p_folder is a Zope (temp) folder or not. - isFolder = folder.meta_type.endswith('Folder') - tool = isFolder and folder.config or folder.getTool() - user = tool.getUser() + # Get the tool. It may not be present yet, maybe are we creating it now. + if folder.meta_type.endswith('Folder'): + # p_folder is a standard Zope (temp) folder. + tool = getattr(folder, 'config', None) + else: + # p_folder is an instance of a gen-class. + tool = folder.getTool() + # Get the currently logged user + user = None + if tool: + user = tool.getUser() + # Checks whether the user an create this object if security is enabled. if not noSecurity: - # Check that the user can create objects of className. klass = ZopeClass.wrapperClass.__bases__[-1] if not tool.userMayCreate(klass): from AccessControl import Unauthorized raise Unauthorized("User can't create instances of %s" % \ klass.__name__) + # Create the object obj = ZopeClass(id) folder._objects = folder._objects + ({'id':id, 'meta_type':className},) folder._setOb(id, obj)