From 91aab1cec449401adcd82eb9696699ee620d0056 Mon Sep 17 00:00:00 2001
From: Fabien Morin <fabien@nexedi.com>
Date: Mon, 24 Nov 2008 16:41:08 +0000
Subject: [PATCH] add a workflow on attachments. Now, if an agent delete an
 attachment, the attachment just pass the transition delete_action and he's
 not deleted as it was before.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24674 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../workflow_chain_type.xml                   |  6 ++++++
 .../PDFDocument_deleteAttachment.xml          | 21 ++++++++++++++++---
 .../PDFDocument_getReportSectionList.xml      |  2 ++
 bt5/erp5_egov/bt/revision                     |  2 +-
 .../template_portal_type_workflow_chain_list  |  1 +
 5 files changed, 28 insertions(+), 4 deletions(-)
 create mode 100644 bt5/erp5_egov/PortalTypeWorkflowChainTemplateItem/workflow_chain_type.xml

diff --git a/bt5/erp5_egov/PortalTypeWorkflowChainTemplateItem/workflow_chain_type.xml b/bt5/erp5_egov/PortalTypeWorkflowChainTemplateItem/workflow_chain_type.xml
new file mode 100644
index 0000000000..de41ca6943
--- /dev/null
+++ b/bt5/erp5_egov/PortalTypeWorkflowChainTemplateItem/workflow_chain_type.xml
@@ -0,0 +1,6 @@
+<workflow_chain>
+ <chain>
+  <type>File</type>
+  <workflow>validation_workflow</workflow>
+ </chain>
+</workflow_chain>
\ No newline at end of file
diff --git a/bt5/erp5_egov/SkinTemplateItem/portal_skins/erp5_egov/PDFDocument_deleteAttachment.xml b/bt5/erp5_egov/SkinTemplateItem/portal_skins/erp5_egov/PDFDocument_deleteAttachment.xml
index 0147c1d381..81c415545e 100644
--- a/bt5/erp5_egov/SkinTemplateItem/portal_skins/erp5_egov/PDFDocument_deleteAttachment.xml
+++ b/bt5/erp5_egov/SkinTemplateItem/portal_skins/erp5_egov/PDFDocument_deleteAttachment.xml
@@ -53,7 +53,9 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>request=context.REQUEST\n
+            <value> <string encoding="cdata"><![CDATA[
+
+request=context.REQUEST\n
 portal = context.getPortalObject()\n
 N_ = portal.Base_translateString\n
 \n
@@ -65,11 +67,20 @@ if id_list == None:\n
 if not same_type(id_list, []):\n
   id_list=[id_list,]\n
 \n
-context.manage_delObjects(id_list)\n
+if len(id_list) >1:\n
+  message = N_("Please+select+only+one+item+to+delete.")\n
+  qs = \'?portal_status_message=%s\' % message\n
+  return request.RESPONSE.redirect( context.absolute_url() + \'/\' + form_id + qs )\n
+\n
+object = getattr(context, id_list[0], None)\n
+portal.portal_workflow.doActionFor(object, \'delete_action\')\n
+#context.manage_delObjects(id_list)\n
 message = N_(\'Attachment ${file_name} has been deleted\', mapping = { \'file_name\': \'"%s"\' % file_name})\n
 qs = \'?portal_status_message=%s\' % message\n
 return request.RESPONSE.redirect( context.absolute_url() + \'/\' + form_id + qs )\n
-</string> </value>
+
+
+]]></string> </value>
         </item>
         <item>
             <key> <string>_code</string> </key>
@@ -123,6 +134,10 @@ return request.RESPONSE.redirect( context.absolute_url() + \'/\' + form_id + qs
                             <string>message</string>
                             <string>qs</string>
                             <string>same_type</string>
+                            <string>len</string>
+                            <string>getattr</string>
+                            <string>_getitem_</string>
+                            <string>object</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_egov/SkinTemplateItem/portal_skins/erp5_egov/PDFDocument_getReportSectionList.xml b/bt5/erp5_egov/SkinTemplateItem/portal_skins/erp5_egov/PDFDocument_getReportSectionList.xml
index 11e83eb886..bf41336842 100644
--- a/bt5/erp5_egov/SkinTemplateItem/portal_skins/erp5_egov/PDFDocument_getReportSectionList.xml
+++ b/bt5/erp5_egov/SkinTemplateItem/portal_skins/erp5_egov/PDFDocument_getReportSectionList.xml
@@ -67,6 +67,8 @@ sub_form_type_list = filter(lambda x: x not in file_type_list, type_list)\n
 viewable_content_list = context.contentValues(portal_type=file_type_list, checked_permission=\'View\')\n
 content_group_dict = {}\n
 for content in viewable_content_list:\n
+  if content.getValidationState() != \'draft\':\n
+    continue\n
   title = content.getTitle()\n
   content_group_dict.setdefault(title, [])\n
   content_group_dict[title].append(content)\n
diff --git a/bt5/erp5_egov/bt/revision b/bt5/erp5_egov/bt/revision
index 9d3f41701a..ee2b836454 100644
--- a/bt5/erp5_egov/bt/revision
+++ b/bt5/erp5_egov/bt/revision
@@ -1 +1 @@
-455
\ No newline at end of file
+456
\ No newline at end of file
diff --git a/bt5/erp5_egov/bt/template_portal_type_workflow_chain_list b/bt5/erp5_egov/bt/template_portal_type_workflow_chain_list
index e69de29bb2..20b97ba57b 100644
--- a/bt5/erp5_egov/bt/template_portal_type_workflow_chain_list
+++ b/bt5/erp5_egov/bt/template_portal_type_workflow_chain_list
@@ -0,0 +1 @@
+File | validation_workflow
\ No newline at end of file
-- 
2.30.9