Commit 0c8c7611 authored by Jérome Perrin's avatar Jérome Perrin

Use allowType in newContent to check if we can create content.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12825 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8d3b00b7
......@@ -77,6 +77,7 @@ class FolderMixIn(ExtensionClass.Base):
This method is public, since TypeInformation.constructInstance will perform
the security check.
"""
pt = self._getTypesTool()
if container is None:
container = self
if id is None:
......@@ -98,14 +99,19 @@ class FolderMixIn(ExtensionClass.Base):
factory_name = 'newTemp%s' %(portal_type.replace(' ', ''))
m = getattr(Document, factory_name)
return m(container, new_id)
self.portal_types.constructContent(type_name=portal_type,
container=container,
id=new_id,
created_by_builder=created_by_builder,
activate_kw=activate_kw,
is_indexable=is_indexable
) # **kw) removed due to CMF bug
myType = pt.getTypeInfo(self)
if myType is not None:
if not myType.allowType( portal_type ):
raise ValueError('Disallowed subobject type: %s' % portal_type)
pt.constructContent( type_name=portal_type,
container=container,
id=new_id,
created_by_builder=created_by_builder,
activate_kw=activate_kw,
is_indexable=is_indexable
) # **kw) removed due to CMF bug
# TODO :the **kw makes it impossible to create content not based on
# ERP5TypeInformation, because factory method often do not support
# keywords arguments.
......
......@@ -146,6 +146,11 @@ class TestFolder(ERP5TypeTestCase, LogInterceptor):
'Add portal content', roles=[], acquire=0)
self._assertAllowedContentTypes(self.other_folder, [])
self._assertAllowedContentTypes(self.folder, type_list)
def test_NewContentAndAllowedContentTypes(self):
self._setAllowedContentTypesForFolderType(('Folder', ))
self.assertRaises(ValueError, self.folder.newContent,
portal_type='Category')
if __name__ == '__main__':
framework()
......
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