[gen] Bugfix in gen.utils.createObject.
This commit is contained in:
parent
5223af2a62
commit
528cca9aa0
|
@ -1 +1 @@
|
||||||
0.8.5
|
0.9.0
|
||||||
|
|
16
gen/utils.py
16
gen/utils.py
|
@ -11,17 +11,25 @@ def createObject(folder, id, className, appName, wf=True, noSecurity=False):
|
||||||
p_wf=False.'''
|
p_wf=False.'''
|
||||||
exec 'from Products.%s.%s import %s as ZopeClass' % \
|
exec 'from Products.%s.%s import %s as ZopeClass' % \
|
||||||
(appName, className, className)
|
(appName, className, className)
|
||||||
# Get the tool. Depends on whether p_folder is a Zope (temp) folder or not.
|
# Get the tool. It may not be present yet, maybe are we creating it now.
|
||||||
isFolder = folder.meta_type.endswith('Folder')
|
if folder.meta_type.endswith('Folder'):
|
||||||
tool = isFolder and folder.config or folder.getTool()
|
# 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()
|
user = tool.getUser()
|
||||||
|
# Checks whether the user an create this object if security is enabled.
|
||||||
if not noSecurity:
|
if not noSecurity:
|
||||||
# Check that the user can create objects of className.
|
|
||||||
klass = ZopeClass.wrapperClass.__bases__[-1]
|
klass = ZopeClass.wrapperClass.__bases__[-1]
|
||||||
if not tool.userMayCreate(klass):
|
if not tool.userMayCreate(klass):
|
||||||
from AccessControl import Unauthorized
|
from AccessControl import Unauthorized
|
||||||
raise Unauthorized("User can't create instances of %s" % \
|
raise Unauthorized("User can't create instances of %s" % \
|
||||||
klass.__name__)
|
klass.__name__)
|
||||||
|
# Create the object
|
||||||
obj = ZopeClass(id)
|
obj = ZopeClass(id)
|
||||||
folder._objects = folder._objects + ({'id':id, 'meta_type':className},)
|
folder._objects = folder._objects + ({'id':id, 'meta_type':className},)
|
||||||
folder._setOb(id, obj)
|
folder._setOb(id, obj)
|
||||||
|
|
Loading…
Reference in a new issue