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