[CMF-checkins] CVS: CMF/CMFStaging - LockTool.py:1.6

Shane Hathaway shane@cvs.zope.org
Fri, 12 Jul 2002 16:43:21 -0400


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

Modified Files:
	LockTool.py 
Log Message:
Added the canChange() method, for detecting whether the user is allowed to
modify the object.


=== CMF/CMFStaging/LockTool.py 1.5 => 1.6 ===
 from AccessControl import ClassSecurityInfo, getSecurityManager
 from Products.CMFCore.utils import UniqueObject, getToolByName, \
      SimpleItemWithProperties, _checkPermission
-from Products.CMFCore.CMFCorePermissions import ManagePortal
+from Products.CMFCore.CMFCorePermissions import ManagePortal, \
+     ModifyPortalContent
 
 from webdav.WriteLockInterface import WriteLockInterface
 from webdav.LockItem import LockItem
@@ -178,7 +179,22 @@
         if _checkPermission(UnlockObjects, object):
             return 1
         return 0
-        
+
+
+    security.declarePublic('canChange')
+    def canChange(self, object):
+        """Returns true if the current user can change the given object."""
+        if not WriteLockInterface.isImplementedBy(object):
+            if self.isLockedOut(object):
+                return 0
+        if not _checkPermission(ModifyPortalContent, object):
+            return 0
+        vt = getToolByName(self, 'portal_versions', None)
+        if vt is not None:
+            if (vt.isUnderVersionControl(object)
+                and not vt.isCheckedOut(object)):
+                return 0
+        return 1
 
 InitializeClass(LockTool)