[CMF-checkins] SVN: CMF/trunk/CMFCore/ - made sure listUndoableTransactionsFor uses the 'object' argument, not ISiteRoot

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


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

Changed:
  U   CMF/trunk/CMFCore/UndoTool.py
  U   CMF/trunk/CMFCore/tests/test_UndoTool.py

-=-
Modified: CMF/trunk/CMFCore/UndoTool.py
===================================================================
--- CMF/trunk/CMFCore/UndoTool.py	2007-07-03 19:55:29 UTC (rev 77379)
+++ CMF/trunk/CMFCore/UndoTool.py	2007-07-03 19:56:05 UTC (rev 77380)
@@ -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 permissions import ListUndoableChanges
 from permissions import ManagePortal
@@ -58,29 +56,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/trunk/CMFCore/tests/test_UndoTool.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_UndoTool.py	2007-07-03 19:55:29 UTC (rev 77379)
+++ CMF/trunk/CMFCore/tests/test_UndoTool.py	2007-07-03 19:56:05 UTC (rev 77380)
@@ -21,15 +21,36 @@
 from zope.interface.verify import verifyClass
 
 
+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_interfaces(self):
         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