From 66cb9c9617417c7139ba4b48ea00209255d2ddf9 Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Thu, 31 Mar 2011 14:07:18 +0200
Subject: [PATCH] Make newContent call _edit sooner (before computing local
 roles)

---
 product/ERP5Type/Core/Folder.py | 17 ++---------------
 product/ERP5Type/ERP5Type.py    | 10 +++++-----
 2 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/product/ERP5Type/Core/Folder.py b/product/ERP5Type/Core/Folder.py
index 9506b0b314..562c02229b 100644
--- a/product/ERP5Type/Core/Folder.py
+++ b/product/ERP5Type/Core/Folder.py
@@ -112,9 +112,7 @@ class FolderMixIn(ExtensionClass.Base):
 
   security.declarePublic('newContent')
   def newContent(self, id=None, portal_type=None, id_group=None,
-          default=None, method=None, container=None, created_by_builder=0,
-          activate_kw=None, is_indexable=None, temp_object=0, reindex_kw=None,
-          compute_local_role=None, notify_workflow=True,  **kw):
+          default=None, method=None, container=None, temp_object=0, **kw):
     """Creates a new content.
     This method is public, since TypeInformation.constructInstance will perform
     the security check.
@@ -157,21 +155,10 @@ class FolderMixIn(ExtensionClass.Base):
     new_instance = type_info.constructInstance(
                            container=container,
                            id=new_id,
-                           created_by_builder=created_by_builder,
                            temp_object=temp_object or temp_container,
-                           activate_kw=activate_kw,
-                           reindex_kw=reindex_kw,
-                           is_indexable=is_indexable,
-                           compute_local_role=compute_local_role,
-                           notify_workflow=notify_workflow,
-                           ) # **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.
+                           **kw)
     if temp_container:
       container._setObject(new_id, new_instance.aq_base)
-    if kw:
-      new_instance._edit(force_update=1, **kw)
     return new_instance
 
   security.declareProtected(
diff --git a/product/ERP5Type/ERP5Type.py b/product/ERP5Type/ERP5Type.py
index 2e67b78d4b..5ed89f447e 100644
--- a/product/ERP5Type/ERP5Type.py
+++ b/product/ERP5Type/ERP5Type.py
@@ -353,7 +353,7 @@ class ERP5TypeInformation(XMLObject,
     security.declarePublic('constructInstance')
     def constructInstance(self, container, id, created_by_builder=0,
                           temp_object=0, compute_local_role=None,
-                          notify_workflow=True, *args, **kw ):
+                          notify_workflow=True, **kw):
       """
       Build a "bare" instance of the appropriate type in
       'container', using 'id' as its id.
@@ -396,13 +396,13 @@ class ERP5TypeInformation(XMLObject,
         if getattr(aq_base(ob), 'uid', None) is None:
           ob.uid = portal.portal_catalog.newUid()
 
-      if kw:
-        ob._edit(force_update=1, **kw)
-
       # Portal type has to be set before setting other attributes
       # in order to initialize aq_dynamic
       ob.portal_type = self.getId()
 
+      if kw:
+        ob._edit(force_update=1, **kw)
+
       if compute_local_role:
         # Do not reindex object because it's already done by manage_afterAdd
         self.updateLocalRolesOnDocument(ob, reindex=False)
@@ -420,7 +420,7 @@ class ERP5TypeInformation(XMLObject,
         if init_script:
           # Acquire the init script in the context of this object
           kw['created_by_builder'] = created_by_builder
-          getattr(ob, init_script)(*args, **kw)
+          getattr(ob, init_script)()
 
       return ob
 
-- 
2.30.9