plone.restapi/unify-expired-and-excluded-items-handling: Return lock info when locking

Thomas Buchberger <jenkins-z4DKO/[email protected]> Sat, 29 Jul 2017 16:31:50 -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/8e12e6504d98f78a06b5316b9b311c5589f54745

Return lock info when locking

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 bf9d34a9..d9fce537 100644
--- a/src/plone/restapi/services/locking/locking.py
+++ b/src/plone/restapi/services/locking/locking.py
@@ -11,8 +11,7 @@ def reply(self):
         lockable = IRefreshableLockable(self.context, None)
         if lockable is not None:
             lockable.lock()
-        self.request.response.setStatus(204)
-        return super(Lock, self).reply()
+        return lock_info(self.context)
 
 
 class Unlock(Service):
@@ -22,8 +21,7 @@ def reply(self):
         lockable = ILockable(self.context)
         if lockable.can_safely_unlock():
             lockable.unlock()
-        self.request.response.setStatus(204)
-        return super(Unlock, self).reply()
+        return lock_info(self.context)
 
 
 class RefreshLock(Service):
@@ -33,24 +31,28 @@ def reply(self):
         lockable = IRefreshableLockable(self.context, None)
         if lockable is not None:
             lockable.refresh_lock()
-        self.request.response.setStatus(204)
-        return super(RefreshLock, self).reply()
+        return lock_info(self.context)
 
 
 class LockInfo(Service):
-    """Returns lock information about an object"""
+    """Lock inforation of an object"""
 
     def reply(self):
-        lockable = ILockable(self.context)
-        if lockable is not None:
-            info = {
-                'locked': lockable.locked(),
-                'stealable': lockable.stealable(),
-            }
-            lock_info = lockable.lock_info()
-            if len(lock_info) > 0:
-                info['creator'] = lock_info[0]['creator']
-                info['time'] = lock_info[0]['time']
-                info['token'] = lock_info[0]['token']
-                info['timeout'] = lock_info[0]['type'].timeout
-            return info
+        return lock_info(self.context)
+
+
+def lock_info(obj):
+    """Returns lock information about the given object."""
+    lockable = ILockable(obj)
+    if lockable is not None:
+        info = {
+            'locked': lockable.locked(),
+            'stealable': lockable.stealable(),
+        }
+        lock_info = lockable.lock_info()
+        if len(lock_info) > 0:
+            info['creator'] = lock_info[0]['creator']
+            info['time'] = lock_info[0]['time']
+            info['token'] = lock_info[0]['token']
+            info['timeout'] = lock_info[0]['type'].timeout
+        return info



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