[Checkins] SVN: Products.CMFCore/trunk/Products/CMFCore/ Added remove support to GenericSetup types tool exportimport handler.

Hanno Schlichting plone at hannosch.info
Sat Oct 11 17:45:12 EDT 2008


Log message for revision 92062:
  Added remove support to GenericSetup types tool exportimport handler.
  

Changed:
  U   Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt
  U   Products.CMFCore/trunk/Products/CMFCore/exportimport/tests/test_typeinfo.py
  U   Products.CMFCore/trunk/Products/CMFCore/exportimport/typeinfo.py

-=-
Modified: Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt	2008-10-11 21:36:55 UTC (rev 92061)
+++ Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt	2008-10-11 21:45:12 UTC (rev 92062)
@@ -4,6 +4,8 @@
 2.2.0 (unreleased)
 ------------------
 
+- Added remove support to GenericSetup types tool exportimport handler.
+
 - FiveActionsTool: Removed the tool and all functionality for bridging
   between Zope 3-style menu items and CMF actions. The CMF has been going
   a different route for a long time and the code is unused and 

Modified: Products.CMFCore/trunk/Products/CMFCore/exportimport/tests/test_typeinfo.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/exportimport/tests/test_typeinfo.py	2008-10-11 21:36:55 UTC (rev 92061)
+++ Products.CMFCore/trunk/Products/CMFCore/exportimport/tests/test_typeinfo.py	2008-10-11 21:45:12 UTC (rev 92062)
@@ -526,7 +526,65 @@
         self.assertEqual(tool.foo._aliases,
                {'(Default)': 'foo_view', 'view': 'foo_view', 'spam': 'eggs'})
 
+    def test_action_remove(self):
+        from Products.CMFCore.exportimport.typeinfo import importTypesTool
 
+        site = self._initSite()
+        tool = site.portal_types
+
+        self.assertEqual(len(tool.objectIds()), 0)
+
+        context = DummyImportContext(site, False)
+
+        # Make sure removing a non-existant action doesn't fail
+        _TOOL = """\
+        <?xml version="1.0"?>
+        <object name="portal_types" meta_type="CMF Types Tool">
+         <object name="%s" meta_type="Factory-based Type Information"/>
+        </object>
+        """
+        context._files['types.xml'] = (_TOOL % 'baz').strip()
+
+        _BAZ_SETUP = """\
+        <?xml version="1.0"?>
+        <object name="%s" meta_type="Factory-based Type Information">
+         <property name="title">Baz</property>
+         <action title="View" action_id="view" category="object"
+            condition_expr="" url_expr="string:${object_url}/baz_view" 
+            icon_expr="" visible="True">
+          <permission value="View"/>
+         </action>
+         <action action_id="edit" category="object" remove="True" />
+        </object>
+        """
+        context._files['types/baz.xml'] = (_BAZ_SETUP % 'baz').strip()
+        importTypesTool(context)
+
+        self.assertEqual(len(tool.objectIds()), 1)
+        self.failUnless('baz' in tool.objectIds())
+        baz = tool['baz']
+        actions = baz.listActions()
+        self.assertEqual(len(actions), 1)
+        self.assertEqual(actions[0].title, 'View')
+
+        # Remove an already existing action
+        _BAZ_REMOVE = """\
+        <?xml version="1.0"?>
+        <object name="%s" meta_type="Factory-based Type Information">
+         <property name="title">Baz</property>
+         <action action_id="view" category="object" remove="True" />
+        </object>
+        """
+        context._files['types/baz.xml'] = (_BAZ_REMOVE % 'baz').strip()
+        importTypesTool(context)
+
+        self.assertEqual(len(tool.objectIds()), 1)
+        self.failUnless('baz' in tool.objectIds())
+        baz = tool['baz']
+        actions = baz.listActions()
+        self.assertEqual(len(actions), 0)
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TypeInformationXMLAdapterTests),

Modified: Products.CMFCore/trunk/Products/CMFCore/exportimport/typeinfo.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/exportimport/typeinfo.py	2008-10-11 21:36:55 UTC (rev 92061)
+++ Products.CMFCore/trunk/Products/CMFCore/exportimport/typeinfo.py	2008-10-11 21:45:12 UTC (rev 92062)
@@ -124,6 +124,7 @@
             action = str(child.getAttribute('url_expr'))
             icon_expr = str(child.getAttribute('icon_expr'))
             visible = self._convertToBoolean(child.getAttribute('visible'))
+            remove = child.hasAttribute('remove') and True or False
             permissions = []
             for sub in child.childNodes:
                 if sub.nodeName != 'permission':
@@ -131,15 +132,23 @@
                 permission = sub.getAttribute('value')
                 permissions.append(permission)
             action_obj = self.context.getActionObject(category+'/'+id)
-            if action_obj is None:
-                self.context.addAction(id, title, action, condition,
-                                       tuple(permissions), category, visible,
-                                       icon_expr=icon_expr)
+            if remove:
+                if action_obj is not None:
+                    # Find the index for the action to remove it
+                    actions = self.context.listActions()
+                    indexes = [(a.category, a.id) for a in actions]
+                    index = indexes.index((category, id))
+                    self.context.deleteActions((index, ))
             else:
-                action_obj.edit(title=title, action=action,
-                                icon_expr=icon_expr, condition=condition,
-                                permissions=tuple(permissions),
-                                visible=visible)
+                if action_obj is None:
+                    self.context.addAction(id, title, action, condition,
+                                           tuple(permissions), category, visible,
+                                           icon_expr=icon_expr)
+                else:
+                    action_obj.edit(title=title, action=action,
+                                    icon_expr=icon_expr, condition=condition,
+                                    permissions=tuple(permissions),
+                                    visible=visible)
 
 
 class TypesToolXMLAdapter(XMLAdapterBase, ObjectManagerHelpers,



More information about the Checkins mailing list