From 14d6a6c62682217a91eefc5e472f1a3faadf8978 Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Sun, 24 May 2009 14:52:16 +0000
Subject: [PATCH] Added extensions from KM project and which can be useful to
 various developers.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27138 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../ExtensionTemplateItem/SecurityCloner.py   |  22 +++
 .../ERP5Type_cloneRoleInformation.xml         | 142 ++++++++++++++++++
 .../erp5_toolbox/cloneRoleInformation.xml     |  31 ++++
 bt5/erp5_forge/bt/template_extension_id_list  |   3 +-
 bt5/erp5_forge/bt/template_local_role_list    |   0
 .../bt/template_portal_type_role_list         |   0
 6 files changed, 197 insertions(+), 1 deletion(-)
 create mode 100644 bt5/erp5_forge/ExtensionTemplateItem/SecurityCloner.py
 create mode 100644 bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Type_cloneRoleInformation.xml
 create mode 100644 bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/cloneRoleInformation.xml
 create mode 100644 bt5/erp5_forge/bt/template_local_role_list
 create mode 100644 bt5/erp5_forge/bt/template_portal_type_role_list

diff --git a/bt5/erp5_forge/ExtensionTemplateItem/SecurityCloner.py b/bt5/erp5_forge/ExtensionTemplateItem/SecurityCloner.py
new file mode 100644
index 0000000000..f56482f5fe
--- /dev/null
+++ b/bt5/erp5_forge/ExtensionTemplateItem/SecurityCloner.py
@@ -0,0 +1,22 @@
+def cloneSecurity(self, from_id, to_id):
+  """
+  This methods copies roles from portal_type
+  from_id to portal_type to_id
+  """
+  s = ''
+  from_pt = self[from_id]
+  to_pt = [self[x] for x in to_id]
+  for pt in to_pt:
+    pt._roles = ()
+    for role in from_pt._roles:
+      pt.addRole(
+      role.getId(),
+      role.Description(),
+      role.Title(),
+      role.getCondition(),
+      '\n'.join(role.getCategory()) or '',
+      role.getBaseCategoryScript(),
+      ' '.join(role.getBaseCategory()) or '',
+      )
+    s+='%s\n' % pt
+  return s
\ No newline at end of file
diff --git a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Type_cloneRoleInformation.xml b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Type_cloneRoleInformation.xml
new file mode 100644
index 0000000000..0a00fb8666
--- /dev/null
+++ b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Type_cloneRoleInformation.xml
@@ -0,0 +1,142 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+        <tuple/>
+      </tuple>
+    </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>"""\n
+  A quite generic script to clone security settings amont portal types.\n
+  from_type - a portal type id\n
+  to_type_list - a list of target types\n
+  Uses external method\n
+"""\n
+\n
+print \'cloning role information from\'\n
+print from_type\n
+if to_type_list == ():\n
+  to_type_list = (to_type,)\n
+print context.cloneRoleInformation(context.portal_types, from_type, to_type_list)\n
+return printed\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>from_type, to_type_list=(), to_type=None</string> </value>
+        </item>
+        <item>
+            <key> <string>errors</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_code</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>co_argcount</string> </key>
+                        <value> <int>3</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>from_type</string>
+                            <string>to_type_list</string>
+                            <string>to_type</string>
+                            <string>_print_</string>
+                            <string>_print</string>
+                            <string>_getattr_</string>
+                            <string>context</string>
+                          </tuple>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_defaults</string> </key>
+            <value>
+              <tuple>
+                <tuple/>
+                <none/>
+              </tuple>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>ERP5Type_cloneRoleInformation</string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/cloneRoleInformation.xml b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/cloneRoleInformation.xml
new file mode 100644
index 0000000000..e15f67414c
--- /dev/null
+++ b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/cloneRoleInformation.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_function</string> </key>
+            <value> <string>cloneSecurity</string> </value>
+        </item>
+        <item>
+            <key> <string>_module</string> </key>
+            <value> <string>SecurityCloner</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>cloneRoleInformation</string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string>Ext. method to clone role information among portal types</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_forge/bt/template_extension_id_list b/bt5/erp5_forge/bt/template_extension_id_list
index e15a755394..ae44ca2d78 100644
--- a/bt5/erp5_forge/bt/template_extension_id_list
+++ b/bt5/erp5_forge/bt/template_extension_id_list
@@ -1,3 +1,4 @@
 Glossary
 PythonScriptParserUtility
-Security
\ No newline at end of file
+Security
+SecurityCloner
\ No newline at end of file
diff --git a/bt5/erp5_forge/bt/template_local_role_list b/bt5/erp5_forge/bt/template_local_role_list
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/bt5/erp5_forge/bt/template_portal_type_role_list b/bt5/erp5_forge/bt/template_portal_type_role_list
new file mode 100644
index 0000000000..e69de29bb2
-- 
2.30.9