plone.restapi/unify-expired-and-excluded-items-handling: Add support to set timeout of locks

Thomas Buchberger <jenkins-z4DKO/[email protected]> Sat, 29 Jul 2017 16:31:57 -0700 (PDT)
Newsgroups gmane.comp.web.zope.plone.cvs
Message-ID <[email protected]>
Repository: plone.restapi
Branch: refs/heads/unify-expired-and-excluded-items-handling
Date: 2017-07-27T10:02:23+02:00
Author: Thomas Buchberger (buchi) <t.buchberger-/8aE7x569Db/[email protected]>
Commit: https://github.com/plone/plone.restapi/commit/2b1252e21970c60adf8b79ea90ef68a30d323d83

Add support to set timeout of locks

Files changed:
M src/plone/restapi/services/locking/locking.py

diff --git a/src/plone/restapi/services/locking/locking.py b/src/plone/restapi/services/locking/locking.py
index d1d67567..37366093 100644
--- a/src/plone/restapi/services/locking/locking.py
+++ b/src/plone/restapi/services/locking/locking.py
@@ -21,6 +21,10 @@ def reply(self):
         if lockable is not None:
             lockable.lock()
 
+            if 'timeout' in data:
+                lock_item = webdav_lock(self.context)
+                lock_item.setTimeout("Second-%s" % data['timeout'])
+
         return lock_info(self.context)
 
 
@@ -72,6 +76,19 @@ def lock_info(obj):
             lock_type = lock_info[0]['type']
             if lock_type:
                 info['name'] = lock_info[0]['type'].__name__
-                info['timeout'] = lock_info[0]['type'].timeout
-
+            lock_item = webdav_lock(obj)
+            if lock_item:
+                info['timeout'] = lock_item.getTimeout()
         return info
+
+
+def webdav_lock(obj):
+    """Returns the WebDAV LockItem"""
+    lockable = ILockable(obj)
+    if lockable is None:
+        return
+
+    lock_info = lockable.lock_info()
+    if len(lock_info) > 0:
+        token = lock_info[0]['token']
+        return obj.wl_getLock(token)



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot