Commit d178a671 authored by Andreas Jung's avatar Andreas Jung

Collector #126: merge from 2.5 branch fixes LOCK-stealing problem

with cadaver
parent bca3e8d5
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""Property sheets""" """Property sheets"""
__version__='$Revision: 1.80 $'[11:-2] __version__='$Revision: 1.81 $'[11:-2]
import time, string, App.Management, Globals import time, string, App.Management, Globals
from webdav.WriteLockInterface import WriteLockInterface from webdav.WriteLockInterface import WriteLockInterface
...@@ -26,6 +26,7 @@ from ExtensionClass import Base ...@@ -26,6 +26,7 @@ from ExtensionClass import Base
from Globals import Persistent from Globals import Persistent
from Traversable import Traversable from Traversable import Traversable
from Acquisition import aq_base from Acquisition import aq_base
from AccessControl import getSecurityManager
class View(App.Management.Tabs, Base): class View(App.Management.Tabs, Base):
"""A view of an object, typically used for management purposes """A view of an object, typically used for management purposes
...@@ -541,13 +542,24 @@ class DAVProperties(Virtual, PropertySheet, View): ...@@ -541,13 +542,24 @@ class DAVProperties(Virtual, PropertySheet, View):
' </n:lockentry>\n ' ' </n:lockentry>\n '
def dav__lockdiscovery(self): def dav__lockdiscovery(self):
security = getSecurityManager()
user = security.getUser().getUserName()
vself = self.v_self() vself = self.v_self()
out = '\n' out = '\n'
if WriteLockInterface.isImplementedBy(vself): if WriteLockInterface.isImplementedBy(vself):
locks = vself.wl_lockValues(killinvalids=1) locks = vself.wl_lockValues(killinvalids=1)
for lock in locks: for lock in locks:
out = '%s\n%s' % (out, lock.asLockDiscoveryProperty('n'))
creator = lock.getCreator()[-1]
if creator == user: fake=0
else: fake=1
out = '%s\n%s' % (out, lock.asLockDiscoveryProperty('n',fake=fake))
out = '%s\n' % out out = '%s\n' % out
return out return out
......
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
# #
############################################################################## ##############################################################################
__version__ = "$Revision: 1.5 $"[11:-2] __version__ = "$Revision: 1.6 $"[11:-2]
from Globals import Persistent from Globals import Persistent
from WriteLockInterface import LockItemInterface from WriteLockInterface import LockItemInterface
...@@ -142,7 +141,10 @@ class LockItem(Persistent): ...@@ -142,7 +141,10 @@ class LockItem(Persistent):
def getLockScope(self): def getLockScope(self):
return self._lockscope return self._lockscope
def asLockDiscoveryProperty(self, ns='d'): def asLockDiscoveryProperty(self, ns='d',fake=0):
if fake: token = 'this-is-a-faked-no-permission-token'
else: token = self._token
s = (' <%(ns)s:activelock>\n' s = (' <%(ns)s:activelock>\n'
' <%(ns)s:locktype><%(ns)s:%(locktype)s/></%(ns)s:locktype>\n' ' <%(ns)s:locktype><%(ns)s:%(locktype)s/></%(ns)s:locktype>\n'
' <%(ns)s:lockscope><%(ns)s:%(lockscope)s/></%(ns)s:lockscope>\n' ' <%(ns)s:lockscope><%(ns)s:%(lockscope)s/></%(ns)s:lockscope>\n'
...@@ -160,11 +162,12 @@ class LockItem(Persistent): ...@@ -160,11 +162,12 @@ class LockItem(Persistent):
'depth': self._depth, 'depth': self._depth,
'owner': self._owner, 'owner': self._owner,
'timeout': self.getTimeoutString(), 'timeout': self.getTimeoutString(),
'locktoken': self._token, 'locktoken': token,
} }
return s return s
def asXML(self): def asXML(self):
s = """<?xml version="1.0" encoding="utf-8" ?> s = """<?xml version="1.0" encoding="utf-8" ?>
<d:prop xmlns:d="DAV:"> <d:prop xmlns:d="DAV:">
<d:lockdiscovery> <d:lockdiscovery>
......
...@@ -13,11 +13,14 @@ ...@@ -13,11 +13,14 @@
"""Commonly used functions for WebDAV support modules.""" """Commonly used functions for WebDAV support modules."""
__version__='$Revision: 1.14 $'[11:-2] __version__='$Revision: 1.15 $'[11:-2]
import time, urllib, re import time, urllib, re
from App.Common import iso8601_date, rfc850_date, rfc1123_date from App.Common import iso8601_date, rfc850_date, rfc1123_date
from App.Common import aq_base from App.Common import aq_base
import random
_randGen = random.Random(time.time())
def absattr(attr): def absattr(attr):
if callable(attr): if callable(attr):
...@@ -53,10 +56,10 @@ def urlbase(url, ftype=urllib.splittype, fhost=urllib.splithost): ...@@ -53,10 +56,10 @@ def urlbase(url, ftype=urllib.splittype, fhost=urllib.splithost):
def generateLockToken(): def generateLockToken():
# Generate a lock token # Generate a lock token
# XXX This is simple right now, just lifted from the original shortcut return '%s-%s-00105A989226:%.03f' % \
# in Resource.dav__genlocktoken, but should be replaced by something (_randGen.random(),_randGen.random(),time.time())
# better.
return 'AA9F6414-1D77-11D3-B825-00105A989226:%.03f' % time.time()
def tokenFinder(token): def tokenFinder(token):
# takes a string like '<opaquelocktoken:afsdfadfadf> and returns the token # takes a string like '<opaquelocktoken:afsdfadfadf> and returns the token
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment