[CMF-checkins] SVN: CMF/branches/2.1/C - made sure listUndoableTransactionsFor uses the 'object' argument, not ISiteRoot

Yvo Schubbe y.2007- at wcm-solutions.de
Tue Jul 3 15:55:30 EDT 2007


Log message for revision 77379:
  - made sure listUndoableTransactionsFor uses the 'object' argument, not ISiteRoot

Changed:
  U   CMF/branches/2.1/CHANGES.txt
  U   CMF/branches/2.1/CMFCore/UndoTool.py
  U   CMF/branches/2.1/CMFCore/tests/test_UndoTool.py

-=-
Modified: CMF/branches/2.1/CHANGES.txt
===================================================================
--- CMF/branches/2.1/CHANGES.txt	2007-07-03 19:52:16 UTC (rev 77378)
+++ CMF/branches/2.1/CHANGES.txt	2007-07-03 19:55:29 UTC (rev 77379)
@@ -11,6 +11,10 @@
 
   Bug Fixes
 
+    - UndoTool: Fixed 'listUndoableTransactionsFor'.
+      The required 'object' argument is now respected. This doesn't change the
+      behavior as long as 'object' is the site root object.
+
     - CMFCore.TypesTool: Corrected method signature of all_meta_types to have
       an interface keyword argument, as per the underlying OFS.ObjectManager
       interface declaration.

Modified: CMF/branches/2.1/CMFCore/UndoTool.py
===================================================================
--- CMF/branches/2.1/CMFCore/UndoTool.py	2007-07-03 19:52:16 UTC (rev 77378)
+++ CMF/branches/2.1/CMFCore/UndoTool.py	2007-07-03 19:55:29 UTC (rev 77379)
@@ -19,11 +19,9 @@
 from Globals import DTMLFile
 from Globals import InitializeClass
 from OFS.SimpleItem import SimpleItem
-from zope.component import queryUtility
 from zope.interface import implements
 
 from exceptions import AccessControl_Unauthorized
-from interfaces import ISiteRoot
 from interfaces import IUndoTool
 from interfaces.portal_undo import portal_undo as z2IUndoTool
 from permissions import ListUndoableChanges
@@ -60,29 +58,23 @@
     manage_overview = DTMLFile( 'explainUndoTool', _dtmldir )
 
     #
-    #   'portal_undo' interface methods
+    #   'IUndoTool' interface methods
     #
     security.declareProtected(ListUndoableChanges, 'listUndoableTransactionsFor')
     def listUndoableTransactionsFor(self, object,
                                     first_transaction=None,
                                     last_transaction=None,
                                     PrincipiaUndoBatchSize=None):
-        '''Lists all transaction IDs the user is allowed to undo.
-        '''
-        # arg list for undoable_transactions() changed in Zope 2.2.
-        portal = queryUtility(ISiteRoot)
-        if portal is None:
-            # fallback
-            portal = self.aq_inner.aq_parent
-
-        transactions = portal.undoable_transactions(
+        """ List all transaction IDs the user is allowed to undo on 'object'.
+        """
+        transactions = object.undoable_transactions(
             first_transaction=first_transaction,
             last_transaction=last_transaction,
             PrincipiaUndoBatchSize=PrincipiaUndoBatchSize)
         for t in transactions:
             # Ensure transaction ids don't have embedded LF.
             t['id'] = t['id'].replace('\n', '')
-        if not _checkPermission(ManagePortal, portal):
+        if not _checkPermission(ManagePortal, object):
             # Filter out transactions done by other members of the portal.
             user_id = _getAuthenticatedUser(self).getId()
             transactions = filter(

Modified: CMF/branches/2.1/CMFCore/tests/test_UndoTool.py
===================================================================
--- CMF/branches/2.1/CMFCore/tests/test_UndoTool.py	2007-07-03 19:52:16 UTC (rev 77378)
+++ CMF/branches/2.1/CMFCore/tests/test_UndoTool.py	2007-07-03 19:55:29 UTC (rev 77379)
@@ -19,24 +19,44 @@
 import Testing
 
 
+class DummyFolder(object):
+
+    def undoable_transactions(self, first_transaction=None,
+                              last_transaction=None,
+                              PrincipiaUndoBatchSize=None):
+        return ()
+
+
 class UndoToolTests(unittest.TestCase):
 
+    def _getTargetClass(self):
+        from Products.CMFCore.UndoTool import UndoTool
+
+        return UndoTool
+
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
     def test_z2interfaces(self):
         from Interface.Verify import verifyClass
         from Products.CMFCore.interfaces.portal_undo \
                 import portal_undo as IUndoTool
-        from Products.CMFCore.UndoTool import UndoTool
 
-        verifyClass(IUndoTool, UndoTool)
+        verifyClass(IUndoTool, self._getTargetClass())
 
     def test_z3interfaces(self):
         from zope.interface.verify import verifyClass
         from Products.CMFCore.interfaces import IUndoTool
-        from Products.CMFCore.UndoTool import UndoTool
 
-        verifyClass(IUndoTool, UndoTool)
+        verifyClass(IUndoTool, self._getTargetClass())
 
+    def test_listUndoableTransactionsFor(self):
+        udtool = self._makeOne()
+        obj = DummyFolder()
+        transactions = udtool.listUndoableTransactionsFor(obj)
+        self.assertEqual(transactions, ())
 
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(UndoToolTests),



More information about the CMF-checkins mailing list