[CMF-checkins] CVS: CMF/CMFStaging - LockTool.py:1.16.4.1
Brian Lloyd
brian at zope.com
Thu Sep 2 17:36:57 EDT 2004
Update of /cvs-repository/CMF/CMFStaging
In directory cvs.zope.org:/tmp/cvs-serv13324
Modified Files:
Tag: CMF-1_4-compatible-branch
LockTool.py
Log Message:
commit changes to 1.4 compatible branch
=== CMF/CMFStaging/LockTool.py 1.16 => 1.16.4.1 ===
--- CMF/CMFStaging/LockTool.py:1.16 Thu Jan 29 18:12:54 2004
+++ CMF/CMFStaging/LockTool.py Thu Sep 2 17:36:57 2004
@@ -33,6 +33,8 @@
from zExceptions import Unauthorized
from staging_utils import verifyPermission
+from BTrees.OOBTree import OOBTree
+from BTrees.OIBTree import OIBTree
# Permission names
LockObjects = 'WebDAV Lock items'
@@ -84,6 +86,32 @@
# 'LockTool' interface methods
#
+
+ security.declarePublic('getLocksForUserId')
+ def getLocksForUserId(self, user_id):
+ """Returns a sequence of path strings representing objects
+ currently locked by the given user id. Each path is a
+ slash-separated path suitable to pass to traversal apis."""
+ mapping = getattr(self, '_locks', None)
+ if mapping is None:
+ return []
+ items = mapping.get(user_id, None)
+ if items is None:
+ return []
+ return items.keys()
+
+ security.declarePrivate('noteLock')
+ def noteLock(self, obj, user_id):
+ mapping = getattr(self, '_locks', None)
+ if mapping is None:
+ mapping = self._locks = OOBTree()
+ path = '/'.join(obj.getPhysicalPath())
+ items = mapping.get(user_id, None)
+ if items is None:
+ items = OIBTree()
+ mapping[user_id] = items
+ items[path] = 1
+
security.declarePublic('lock')
def lock(self, obj):
"""Locks an object.
@@ -103,7 +131,19 @@
user = getSecurityManager().getUser()
lockitem = LockItem(user, timeout=(self.timeout_days * 86400))
obj.wl_setLock(lockitem.getLockToken(), lockitem)
+ self.noteLock(obj, user.getId())
+ security.declarePrivate('noteUnlock')
+ def noteUnlock(self, obj, user_id):
+ mapping = getattr(self, '_locks', None)
+ if mapping is None:
+ return
+ path = '/'.join(obj.getPhysicalPath())
+ items = mapping.get(user_id, None)
+ if items is None:
+ return
+ if items.get(path):
+ del items[path]
security.declarePublic('breaklock')
def breaklock(self, obj, message=''):
@@ -118,6 +158,8 @@
if (vt.isUnderVersionControl(obj)
and vt.isCheckedOut(obj)):
vt.checkin(obj, message)
+ if locker:
+ self.noteUnlock(obj, locker)
security.declarePublic('unlock')
@@ -146,6 +188,7 @@
and vt.isCheckedOut(obj)):
vt.checkin(obj, message)
+ self.noteUnlock(obj, locker)
security.declarePublic('locker')
def locker(self, obj):
More information about the CMF-checkins
mailing list