From 2658125bfa378fc73a0f5e8604157dffd782c75d Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Wed, 26 Jun 2013 21:30:05 +0900
Subject: [PATCH] ZODB Components: Must be able to really delete a Component
 and not only in 'deleted' state.

Folder_delete calls Workflow 'delete_action' if the object has any Workflow
History. Before, component_validation_workflow was acting like
validation_workflow for deleting objects, e.g. 'delete_action' triggers
'delete' state which is fine for normal documents but not Components.
---
 .../component_validation_workflow.xml         |  2 +-
 .../scripts/deleteObject.xml                  | 69 +++++++++++++++++++
 .../transitions/delete.xml                    | 58 ----------------
 .../transitions/delete_action.xml             |  6 +-
 .../ERP5/bootstrap/erp5_core/bt/change_log    |  3 +
 product/ERP5/bootstrap/erp5_core/bt/revision  |  2 +-
 .../tests/testDynamicClassGeneration.py       | 13 +++-
 7 files changed, 91 insertions(+), 62 deletions(-)
 create mode 100644 product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/scripts/deleteObject.xml
 delete mode 100644 product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/delete.xml

diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow.xml
index 3591bbec33..e0980777e6 100644
--- a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow.xml
+++ b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow.xml
@@ -52,7 +52,7 @@
         </item>
         <item>
             <key> <string>title</string> </key>
-            <value> <string>Validation Workflow</string> </value>
+            <value> <string>Component Validation Workflow</string> </value>
         </item>
       </dictionary>
     </pickle>
diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/scripts/deleteObject.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/scripts/deleteObject.xml
new file mode 100644
index 0000000000..4544c8dc49
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/scripts/deleteObject.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>name_container</string> </key>
+                                <value> <string>container</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_context</string> </key>
+                                <value> <string>context</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_m_self</string> </key>
+                                <value> <string>script</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_body</string> </key>
+            <value> <string>document = state_change[\'object\']\n
+container = document.getParentValue()\n
+container.manage_delObjects(ids=[document.getId()])\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>state_change</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>deleteObject</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/delete.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/delete.xml
deleted file mode 100644
index c258c14dec..0000000000
--- a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/delete.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-<?xml version="1.0"?>
-<ZopeData>
-  <record id="1" aka="AAAAAAAAAAE=">
-    <pickle>
-      <global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/>
-    </pickle>
-    <pickle>
-      <dictionary>
-        <item>
-            <key> <string>actbox_category</string> </key>
-            <value> <string>workflow</string> </value>
-        </item>
-        <item>
-            <key> <string>actbox_name</string> </key>
-            <value> <string></string> </value>
-        </item>
-        <item>
-            <key> <string>actbox_url</string> </key>
-            <value> <string></string> </value>
-        </item>
-        <item>
-            <key> <string>after_script_name</string> </key>
-            <value> <string></string> </value>
-        </item>
-        <item>
-            <key> <string>description</string> </key>
-            <value> <string>Delete a document in ERP5</string> </value>
-        </item>
-        <item>
-            <key> <string>guard</string> </key>
-            <value>
-              <none/>
-            </value>
-        </item>
-        <item>
-            <key> <string>id</string> </key>
-            <value> <string>delete</string> </value>
-        </item>
-        <item>
-            <key> <string>new_state_id</string> </key>
-            <value> <string>deleted</string> </value>
-        </item>
-        <item>
-            <key> <string>script_name</string> </key>
-            <value> <string></string> </value>
-        </item>
-        <item>
-            <key> <string>title</string> </key>
-            <value> <string>Delete</string> </value>
-        </item>
-        <item>
-            <key> <string>trigger_type</string> </key>
-            <value> <int>2</int> </value>
-        </item>
-      </dictionary>
-    </pickle>
-  </record>
-</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/delete_action.xml b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/delete_action.xml
index 8dbec5ba9e..cf6ab50f8a 100644
--- a/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/delete_action.xml
+++ b/product/ERP5/bootstrap/erp5_core/WorkflowTemplateItem/portal_workflow/component_validation_workflow/transitions/delete_action.xml
@@ -10,6 +10,10 @@
             <key> <string>actbox_category</string> </key>
             <value> <string>workflow</string> </value>
         </item>
+        <item>
+            <key> <string>actbox_icon</string> </key>
+            <value> <string></string> </value>
+        </item>
         <item>
             <key> <string>actbox_name</string> </key>
             <value> <string></string> </value>
@@ -20,7 +24,7 @@
         </item>
         <item>
             <key> <string>after_script_name</string> </key>
-            <value> <string>delete</string> </value>
+            <value> <string>deleteObject</string> </value>
         </item>
         <item>
             <key> <string>description</string> </key>
diff --git a/product/ERP5/bootstrap/erp5_core/bt/change_log b/product/ERP5/bootstrap/erp5_core/bt/change_log
index 74223a7068..b62d91c6a9 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/change_log
+++ b/product/ERP5/bootstrap/erp5_core/bt/change_log
@@ -1,3 +1,6 @@
+2013-06-26 arnaud.fontaine
+* ZODB Components: Must be able to really delete a Component and not only in 'deleted' state. Folder_delete calls Workflow 'delete_action' if the object has any Workflow History. Before, component_validation_workflow was acting like validation_workflow for deleting objects, e.g. 'delete_action' triggers 'delete' state which is fine for normal documents but not Components.
+
 2013-06-25 arnaud.fontaine
 * ZODB Components: Migration must be all or nothing to avoid partial modifications of bt5 properties.
 
diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision
index ecd1223e49..987b53e30c 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/revision
+++ b/product/ERP5/bootstrap/erp5_core/bt/revision
@@ -1 +1 @@
-41101
\ No newline at end of file
+41102
\ No newline at end of file
diff --git a/product/ERP5Type/tests/testDynamicClassGeneration.py b/product/ERP5Type/tests/testDynamicClassGeneration.py
index 37be08b38d..0a2d11eb1c 100644
--- a/product/ERP5Type/tests/testDynamicClassGeneration.py
+++ b/product/ERP5Type/tests/testDynamicClassGeneration.py
@@ -1343,7 +1343,7 @@ class _TestZodbComponent(SecurityTestCase):
                       fromlist=[self._getComponentModuleName()],
                       level=0)
 
-  def testValidateInvalidate(self):
+  def testValidateInvalidateDelete(self):
     """
     The new Component should only be in erp5.component.XXX when validated,
     otherwise it should not be importable at all
@@ -1364,6 +1364,17 @@ class _TestZodbComponent(SecurityTestCase):
     self.tic()
     self.assertModuleImportable('TestValidateInvalidateComponent')
 
+    test_component.invalidate()
+    self.tic()
+    self.failIfModuleImportable('TestValidateInvalidateComponent')
+
+    self.portal.portal_workflow.doActionFor(test_component, 'delete_action')
+    self.tic()
+    self.failIfModuleImportable('TestValidateInvalidateComponent')
+    self.assertEqual([o for o in self.portal.portal_components.contentValues()
+                      if o.getReference() == 'TestValidateInvalidateComponent'],
+                     [])
+
   def testReferenceWithReservedKeywords(self):
     """
     Check whether checkConsistency has been properly implemented for checking
-- 
2.30.9