[CMF-checkins] CVS: CMF/CMFStaging - LockTool.py:1.2 StagingTool.py:1.3 VersionsTool.py:1.2

Shane Hathaway shane@cvs.zope.org
Mon, 13 May 2002 12:32:12 -0400


Update of /cvs-repository/CMF/CMFStaging
In directory cvs.zope.org:/tmp/cvs-serv10775

Modified Files:
	LockTool.py StagingTool.py VersionsTool.py 
Log Message:
Integrated three optional kinds of automation: the lock tool's auto_version
flag enables automatic checkin / checkout, the staging tool's auto_checkin
flag enables automatic unlock and checkin on staging, and the version tool's
auto_copy_forward flag enables skipping over revisions when checking out.


=== CMF/CMFStaging/LockTool.py 1.1.1.1 => 1.2 ===
                      ) + SimpleItem.manage_options
 
+    # With auto_version on, locking automatically causes a version checkout
+    # and unlocking automatically causes a checkin.  This is one form
+    # of autoversioning described in the DeltaV introduction.
+    # Should be configurable TTW.
+    # http://www.webdav.org/deltav/WWW10/deltav-intro.htm
+    auto_version = 1
+
     #
     #   ZMI methods
     #
@@ -66,12 +73,17 @@
     security.declareProtected(LockObjects, 'lock')
     def lock(self, object):
         '''Locks an object'''
-        user = getSecurityManager().getUser()
         locker = self.locker(object)
-
         if locker:
             raise LockingError, '%s is already locked' % pathOf(object)
 
+        if self.auto_version:
+            vt = getToolByName(self, 'portal_versions', None)
+            if vt is not None:
+                if not vt.isCheckedOut(object):
+                    object = vt.checkout(object)
+
+        user = getSecurityManager().getUser()
         lockitem = LockItem(user)
         object.wl_setLock(lockitem.getLockToken(), lockitem)
 
@@ -80,7 +92,6 @@
     def unlock(self, object):
         '''Unlocks an object'''
         locker = self.locker(object)
-
         if not locker:
             raise LockingError, ("Unlocking an unlocked item: %s" %
                                  pathOf(object))
@@ -93,6 +104,11 @@
         # According to WriteLockInterface, we shouldn't call
         # wl_clearLocks(), but it seems like the right thing to do anyway.
         object.wl_clearLocks()
+
+        if self.auto_version:
+            vt = getToolByName(self, 'portal_versions', None)
+            if vt is not None:
+                vt.checkin(object)
 
 
     security.declarePublic('locker')


=== CMF/CMFStaging/StagingTool.py 1.2 => 1.3 ===
 
 from Acquisition import aq_inner, aq_parent, aq_acquire
-from Products.CMFCore.utils import UniqueObject
-from Products.CMFCore.CMFCorePermissions import ManagePortal
 from OFS.SimpleItem import SimpleItem
 from Globals import InitializeClass
 from AccessControl import ClassSecurityInfo
 
+from Products.CMFCore.utils import UniqueObject, getToolByName
+from Products.CMFCore.CMFCorePermissions import ManagePortal
+
 # Permission name
 StageObjects = 'Use version control'
 
@@ -44,6 +45,10 @@
                      , 
                      ) + SimpleItem.manage_options
 
+    # With auto_unlock_checkin turned on, updateStages() uses the
+    # lock tool and the versions tool to unlock and check in the object.
+    auto_checkin = 1
+
     # _stages maps stage names to relative paths.
     # This should be configurable TTW.
     _stages = {
@@ -109,6 +114,17 @@
         return res
 
 
+    def _autoCheckin(self, object):
+        lt = getToolByName(self, 'portal_lock', None)
+        if lt is not None:
+            if lt.locked(object):
+                lt.unlock(object)
+        vt = getToolByName(self, 'portal_versions', None)
+        if vt is not None:
+            if vt.isCheckedOut(object):
+                vt.checkin(object)
+
+
     security.declareProtected(StageObjects, 'isStageable')
     def isStageable(self, object):
         """Returns a true value if the object can be staged."""
@@ -123,9 +139,15 @@
         in the specified stage."""
         if from_stage in to_stages or not self._stages.has_key(from_stage):
             raise StagingError, "Invalid from_stages or to_stages parameter."
+
         repo = self._getVersionRepository()
-        object_map = self._getObjectStages(object)
         container_map = self._getObjectStages(object, get_container=1)
+
+        self._checkContainers(object, to_stages, container_map)
+        if self.auto_checkin:
+            self._autoCheckin(object)
+
+        object_map = self._getObjectStages(object)
         dev_object = object_map[from_stage]
         version_info = repo.getVersionInfo(dev_object)
         version_id = version_info.version_id
@@ -186,20 +208,23 @@
         return self._getObjectVersionIds(object)
 
 
-    security.declareProtected(StageObjects, 'checkContainer')
-    def checkContainer(self, object, stage):
+    def _checkContainers(self, object, stages, containers):
+        for stage in stages:
+            if containers.get(stage) is None:
+                p = '/'.join(object.getPhysicalPath())
+                raise StagingError, (
+                    'The container for "%s" does not exist on "%s"'
+                    % (p, stage))
+
+
+    security.declareProtected(StageObjects, 'checkContainers')
+    def checkContainers(self, object, stages):
         """Verifies that the container exists for the object on the
-        given stage.  If not, an exception is raised.
+        given stages.  If not, an exception is raised.
         """
-        stages = self._getObjectStages(object, get_container=1)
-        container = stages[stage]
-        if container is not None:
-            return 1
-        else:
-            p = '/'.join(object.getPhysicalPath())
-            raise StagingError, (
-                'The container for "%s" does not exist on "%s"'
-                % (p, stage))
+        containers = self._getObjectStages(object, get_container=1)
+        self._checkContainers(object, stages, containers)
+        return 1
 
 
     security.declareProtected(StageObjects, 'getURLForStage')


=== CMF/CMFStaging/VersionsTool.py 1.1.1.1 => 1.2 ===
                      ) + SimpleItem.manage_options
 
+
+    # With auto_copy_forward turned on, the versions tool lets users
+    # check out an object even if it is not updated to the latest
+    # revision.  It copies the old revision forward.  Note that
+    # this feature really shouldn't be enabled unless users also have the
+    # ability to revert to specific revisions.
+    auto_copy_forward = 1
+
     security.declareProtected(ManagePortal, 'manage_overview' )
     #manage_overview = DTMLFile( 'explainVersionsTool', _dtmldir )
 
@@ -59,7 +67,7 @@
         old_state = None
         if not repo.isUnderVersionControl(object):
             repo.applyVersionControl(object)
-        elif not repo.isResourceUpToDate(object):
+        elif self.auto_copy_forward and not repo.isResourceUpToDate(object):
             # Copy the old state forward after the object has been checked out.
             info = repo.getVersionInfo(object)
             old_state = repo.getVersionOfResource(