Commit 2a8b7fe8 authored by Kevin Deldycke's avatar Kevin Deldycke

Klaus: Raise exception when there is no allowed content type


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4055 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6481a2a2
...@@ -59,7 +59,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -59,7 +59,7 @@ class FolderMixIn(ExtensionClass.Base):
security.declareObjectProtected(Permissions.View) security.declareObjectProtected(Permissions.View)
security.declareProtected(Permissions.AddPortalContent, 'newContent') security.declareProtected(Permissions.AddPortalContent, 'newContent')
def newContent(self, id=None, portal_type=None, id_group=None, def newContent(self, id=None, portal_type=None, id_group=None,
default=None, method=None, immediate_reindex=0, default=None, method=None, immediate_reindex=0,
container=None, bypass_init_script=0, **kw): container=None, bypass_init_script=0, **kw):
""" """
...@@ -71,6 +71,8 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -71,6 +71,8 @@ class FolderMixIn(ExtensionClass.Base):
new_id = str(container.generateNewId(id_group = id_group, default=default, method=method)) new_id = str(container.generateNewId(id_group = id_group, default=default, method=method))
else: else:
new_id = str(id) new_id = str(id)
if not container.allowedContentTypes():
raise 'NoAllowedContenTypesError'
if portal_type is None: portal_type = container.allowedContentTypes()[0].id if portal_type is None: portal_type = container.allowedContentTypes()[0].id
self.portal_types.constructContent(type_name=portal_type, self.portal_types.constructContent(type_name=portal_type,
container=container, container=container,
...@@ -85,9 +87,9 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -85,9 +87,9 @@ class FolderMixIn(ExtensionClass.Base):
security.declareProtected( security.declareProtected(
Permissions.DeletePortalContent, 'deleteContent') Permissions.DeletePortalContent, 'deleteContent')
def deleteContent(self, id): def deleteContent(self, id):
""" delete items in this folder. """ delete items in this folder.
`id` can be a list or a string. `id` can be a list or a string.
""" """
if type(id) is type(''): if type(id) is type(''):
self._delObject(id) self._delObject(id)
elif type(id) is type([]) or type(id) is type(()): elif type(id) is type([]) or type(id) is type(()):
...@@ -140,7 +142,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -140,7 +142,7 @@ class FolderMixIn(ExtensionClass.Base):
""" """
if not kw.has_key('parent_uid'): #WHY ???? if not kw.has_key('parent_uid'): #WHY ????
kw['parent_uid'] = self.getUid() kw['parent_uid'] = self.getUid()
# Make sure that if we use parent base category # Make sure that if we use parent base category
# We do not have conflicting parent uid values # We do not have conflicting parent uid values
delete_parent_uid = 0 delete_parent_uid = 0
...@@ -152,7 +154,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -152,7 +154,7 @@ class FolderMixIn(ExtensionClass.Base):
delete_parent_uid = 1 delete_parent_uid = 1
if delete_parent_uid: if delete_parent_uid:
del kw['parent_uid'] del kw['parent_uid']
kw2 = {} kw2 = {}
# Remove useless matter before calling the # Remove useless matter before calling the
# catalog. In particular, consider empty # catalog. In particular, consider empty
...@@ -173,7 +175,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -173,7 +175,7 @@ class FolderMixIn(ExtensionClass.Base):
""" """
if not kw.has_key('parent_uid'): #WHY ???? if not kw.has_key('parent_uid'): #WHY ????
kw['parent_uid'] = self.getUid() kw['parent_uid'] = self.getUid()
# Make sure that if we use parent base category # Make sure that if we use parent base category
# We do not have conflicting parent uid values # We do not have conflicting parent uid values
delete_parent_uid = 0 delete_parent_uid = 0
...@@ -185,7 +187,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -185,7 +187,7 @@ class FolderMixIn(ExtensionClass.Base):
delete_parent_uid = 1 delete_parent_uid = 1
if delete_parent_uid: if delete_parent_uid:
del kw['parent_uid'] del kw['parent_uid']
kw2 = {} kw2 = {}
# Remove useless matter before calling the # Remove useless matter before calling the
# catalog. In particular, consider empty # catalog. In particular, consider empty
...@@ -197,8 +199,8 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -197,8 +199,8 @@ class FolderMixIn(ExtensionClass.Base):
# content has to be called z_search_folder # content has to be called z_search_folder
method = self.portal_catalog.countResults method = self.portal_catalog.countResults
return method(**kw2) return method(**kw2)
# Count objects in the folder # Count objects in the folder
security.declarePrivate('_count') security.declarePrivate('_count')
def _count(self, **kw): def _count(self, **kw):
...@@ -289,10 +291,10 @@ be a problem).""" ...@@ -289,10 +291,10 @@ be a problem)."""
_edit = Base._edit _edit = Base._edit
_setPropValue = Base._setPropValue _setPropValue = Base._setPropValue
_propertyMap = Base._propertyMap # are there any others XXX ? _propertyMap = Base._propertyMap # are there any others XXX ?
# CPS patch circumvent # CPS patch circumvent
manage_renameObject = OriginalCopyContainer.manage_renameObject manage_renameObject = OriginalCopyContainer.manage_renameObject
#security.declareProtected( Permissions.DeletePortalContent, 'manage_delObjects' ) #security.declareProtected( Permissions.DeletePortalContent, 'manage_delObjects' )
#manage_delObjects = CopyContainer.manage_delObjects #manage_delObjects = CopyContainer.manage_delObjects
...@@ -491,7 +493,7 @@ be a problem).""" ...@@ -491,7 +493,7 @@ be a problem)."""
""" """
# In ERP5, simply reindex all objects. # In ERP5, simply reindex all objects.
self.recursiveReindexObject() self.recursiveReindexObject()
security.declarePublic( 'recursiveReindexObject' ) security.declarePublic( 'recursiveReindexObject' )
def recursiveReindexObject(self, *args, **kw): def recursiveReindexObject(self, *args, **kw):
""" """
...@@ -502,7 +504,7 @@ be a problem).""" ...@@ -502,7 +504,7 @@ be a problem)."""
root_indexable = int(getattr(self.getPortalObject(),'isIndexable',1)) root_indexable = int(getattr(self.getPortalObject(),'isIndexable',1))
if self.isIndexable and root_indexable: if self.isIndexable and root_indexable:
self.activate(group_method_id='portal_catalog/catalogObjectList', expand_method_id='getIndexableChildValueList', **kw).recursiveImmediateReindexObject(*args, **kw) self.activate(group_method_id='portal_catalog/catalogObjectList', expand_method_id='getIndexableChildValueList', **kw).recursiveImmediateReindexObject(*args, **kw)
security.declareProtected( Permissions.AccessContentsInformation, 'getIndexableChildValueList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getIndexableChildValueList' )
def getIndexableChildValueList(self): def getIndexableChildValueList(self):
""" """
...@@ -515,7 +517,7 @@ be a problem).""" ...@@ -515,7 +517,7 @@ be a problem)."""
if hasattr(aq_base(c), 'getIndexableChildValueList'): if hasattr(aq_base(c), 'getIndexableChildValueList'):
value_list.extend(c.getIndexableChildValueList()) value_list.extend(c.getIndexableChildValueList())
return value_list return value_list
security.declarePublic( 'recursiveImmediateReindexObject' ) security.declarePublic( 'recursiveImmediateReindexObject' )
def recursiveImmediateReindexObject(self, *args, **kw): def recursiveImmediateReindexObject(self, *args, **kw):
""" """
...@@ -573,14 +575,14 @@ be a problem).""" ...@@ -573,14 +575,14 @@ be a problem)."""
btree_ok = self._cleanup() btree_ok = self._cleanup()
if not btree_ok: if not btree_ok:
# We must commit if we want to keep on recursing # We must commit if we want to keep on recursing
get_transaction().commit() get_transaction().commit()
error_list += [(self.getRelativeUrl(), 'BTree Inconsistency', error_list += [(self.getRelativeUrl(), 'BTree Inconsistency',
199, '(fixed)')] 199, '(fixed)')]
# Call superclass # Call superclass
error_list += Base.checkConsistency(self, fixit=fixit) error_list += Base.checkConsistency(self, fixit=fixit)
# We must commit before listing folder contents # We must commit before listing folder contents
# in case we erased some data # in case we erased some data
if fixit: get_transaction().commit() if fixit: get_transaction().commit()
# Then check the consistency on all sub objects # Then check the consistency on all sub objects
for object in self.contentValues(): for object in self.contentValues():
if fixit: if fixit:
...@@ -640,21 +642,21 @@ be a problem).""" ...@@ -640,21 +642,21 @@ be a problem)."""
# Aliases # Aliases
getObjectIds = CMFBTreeFolder.objectIds getObjectIds = CMFBTreeFolder.objectIds
# Overloading # Overloading
security.declareProtected( Permissions.AccessContentsInformation, 'getParentSqlExpression' ) security.declareProtected( Permissions.AccessContentsInformation, 'getParentSqlExpression' )
def getParentSqlExpression(self, table = 'catalog', strict_membership = 0): def getParentSqlExpression(self, table = 'catalog', strict_membership = 0):
""" """
Builds an SQL expression to search children and subclidren Builds an SQL expression to search children and subclidren
""" """
if strict_membership: if strict_membership:
return Base.getParentSqlExpression(self, table=table, strict_membership=strict_membership) return Base.getParentSqlExpression(self, table=table, strict_membership=strict_membership)
result = "%s.parent_uid = %s" % (table, self.getUid()) result = "%s.parent_uid = %s" % (table, self.getUid())
for o in self.objectValues(): for o in self.objectValues():
if hasattr(aq_base(o), 'objectValues'): if hasattr(aq_base(o), 'objectValues'):
# Do not consider non folder objects # Do not consider non folder objects
result = "%s OR %s" % (result, o.getParentSqlExpression(table=table, strict_membership=strict_membership)) result = "%s OR %s" % (result, o.getParentSqlExpression(table=table, strict_membership=strict_membership))
return "( %s )" % result return "( %s )" % result
def mergeContent(self,from_object=None,to_object=None, delete=1,**kw): def mergeContent(self,from_object=None,to_object=None, delete=1,**kw):
""" """
...@@ -694,7 +696,7 @@ be a problem).""" ...@@ -694,7 +696,7 @@ be a problem)."""
parent = from_object.getParent() parent = from_object.getParent()
parent.manage_delObjects(from_object.getId()) parent.manage_delObjects(from_object.getId())
return corrected_list return corrected_list
security.declareProtected( Permissions.AccessContentsInformation, 'objectValues' ) security.declareProtected( Permissions.AccessContentsInformation, 'objectValues' )
def objectValues(self, spec=None, meta_type=None, portal_type=None, sort_on=None, **kw): def objectValues(self, spec=None, meta_type=None, portal_type=None, sort_on=None, **kw):
#LOG('objectValues', 0, 'spec = %r, kw = %r' % (spec, kw)) #LOG('objectValues', 0, 'spec = %r, kw = %r' % (spec, kw))
...@@ -703,7 +705,7 @@ be a problem).""" ...@@ -703,7 +705,7 @@ be a problem)."""
object_list = CMFBTreeFolder.objectValues(self, spec=spec) object_list = CMFBTreeFolder.objectValues(self, spec=spec)
if portal_type is not None: if portal_type is not None:
if type(portal_type) == type(''): if type(portal_type) == type(''):
portal_type = (portal_type,) portal_type = (portal_type,)
object_list = filter(lambda x: x.getPortalType() in portal_type, object_list) object_list = filter(lambda x: x.getPortalType() in portal_type, object_list)
if sort_on is not None: if sort_on is not None:
def cmpObjects(x, y): def cmpObjects(x, y):
...@@ -712,10 +714,10 @@ be a problem).""" ...@@ -712,10 +714,10 @@ be a problem)."""
if result != 0: if result != 0:
return result return result
return 0 return 0
object_list.sort(cmpObjects) object_list.sort(cmpObjects)
return object_list return object_list
# Override security declaration of CMFCore/PortalFolder (used by CMFBTreeFolder) # Override security declaration of CMFCore/PortalFolder (used by CMFBTreeFolder)
security.declareProtected(Permissions.ModifyPortalContent,'setDescription') security.declareProtected(Permissions.ModifyPortalContent,'setDescription')
security.declareProtected( Permissions.ModifyPortalContent, 'setTitle' ) security.declareProtected( Permissions.ModifyPortalContent, 'setTitle' )
......
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