[CMF-checkins] SVN: CMF/branches/1.6/C Fixed import of actions from
extension profiles, now they don't
Florent Guillaume
fg at nuxeo.com
Fri Jan 20 07:56:59 EST 2006
Log message for revision 41382:
Fixed import of actions from extension profiles, now they don't
overwrite all previous actions in the action provider.
Changed:
U CMF/branches/1.6/CHANGES.txt
U CMF/branches/1.6/CMFCore/exportimport/actions.py
U CMF/branches/1.6/CMFCore/exportimport/tests/test_actions.py
-=-
Modified: CMF/branches/1.6/CHANGES.txt
===================================================================
--- CMF/branches/1.6/CHANGES.txt 2006-01-20 11:35:10 UTC (rev 41381)
+++ CMF/branches/1.6/CHANGES.txt 2006-01-20 12:56:59 UTC (rev 41382)
@@ -4,6 +4,9 @@
- Removed BBBTransaction class from CMFCore.utils
+ - Fixed import of actions from extension profiles, now they don't
+ overwrite all previous actions in the action provider.
+
Features
- Replaced Z2 interfaces w/ Z3 interfaces, dynamically creating Z2
Modified: CMF/branches/1.6/CMFCore/exportimport/actions.py
===================================================================
--- CMF/branches/1.6/CMFCore/exportimport/actions.py 2006-01-20 11:35:10 UTC (rev 41381)
+++ CMF/branches/1.6/CMFCore/exportimport/actions.py 2006-01-20 12:56:59 UTC (rev 41382)
@@ -122,11 +122,12 @@
if provider_id not in self.context.listActionProviders():
self.context.addActionProvider(provider_id)
- # delete any actions that are auto-created
- provider = getToolByName(self.context, provider_id)
- num_actions = len(provider.listActions())
- if num_actions:
- provider.deleteActions(range(0,num_actions))
+ if self.environ.shouldPurge():
+ # Delete provider's actions
+ provider = getToolByName(self.context, provider_id)
+ num_actions = len(provider.listActions())
+ if num_actions:
+ provider.deleteActions(range(0, num_actions))
# BBB: for CMF 1.5 profiles
self._initOldstyleActions(child)
@@ -164,6 +165,12 @@
if permission:
break
+ # Remove previous action with same id and category.
+ old = [i for (i, action) in enumerate(provider.listActions())
+ if action.id == action_id and action.category == category]
+ if old:
+ provider.deleteActions(old)
+
provider.addAction(action_id, title, url_expr,
condition_expr, permission,
category, visible)
Modified: CMF/branches/1.6/CMFCore/exportimport/tests/test_actions.py
===================================================================
--- CMF/branches/1.6/CMFCore/exportimport/tests/test_actions.py 2006-01-20 11:35:10 UTC (rev 41381)
+++ CMF/branches/1.6/CMFCore/exportimport/tests/test_actions.py 2006-01-20 12:56:59 UTC (rev 41382)
@@ -342,6 +342,49 @@
self._compareDOM(text, _NORMAL_EXPORT)
self.assertEqual(content_type, 'text/xml')
+ def test_import_extension(self):
+ from Products.CMFCore.exportimport.actions import importActionProviders
+
+ site = self._initSite(2, 2)
+ atool = site.portal_actions
+ foo = site.portal_foo
+ bar = site.portal_bar
+
+ # Normal import.
+ context = DummyImportContext(site)
+ context._files['actions.xml'] = _NORMAL_EXPORT
+ importActionProviders(context)
+
+ self.assertEqual(len(atool.listActionProviders()), 3)
+ self.assertEqual([a.id for a in foo.listActions()], ['foo'])
+ self.assertEqual([a.id for a in bar.listActions()], ['bar'])
+
+ # Add an action manually to bar, it shouldn't get
+ # removed by the next non-purge import.
+ bar.addAction(id='gee',
+ name='Gee',
+ action='geeman',
+ condition='python:maybe()',
+ permission=('Manage portal',),
+ category='dummy',
+ visible=0)
+ # Modify actions.
+ foo.listActions()[0].title = 'OtherFoo'
+ bar.listActions()[0].title = 'OtherBar'
+
+ self.assertEqual([a.id for a in bar.listActions()], ['bar', 'gee'])
+
+ # Now reimport as extension profile, without purge.
+ context = DummyImportContext(site, False)
+ context._files['actions.xml'] = _NORMAL_EXPORT
+ importActionProviders(context)
+
+ self.assertEqual(len(atool.listActionProviders()), 3)
+ self.assertEqual([a.id for a in foo.listActions()], ['foo'])
+ self.assertEqual(foo.listActions()[0].title, 'Foo')
+ self.assertEqual([a.id for a in bar.listActions()], ['gee', 'bar'])
+ self.assertEqual([a.title for a in bar.listActions()], ['Gee', 'Bar'])
+
def test_remove_skip_purge(self):
from Products.CMFCore.exportimport.actions \
import importActionProviders
More information about the CMF-checkins
mailing list