def stealable(self, lock_type=STEALABLE_LOCK): """Copied from plone.locking.lockable.TTWLockable Find out if the lock can be stolen. This means: - the lock type is stealable; and - the object is not marked with INonStealableLock; or - can_safely_unlock() is true. """ # If the lock type is not stealable ever, return False if not lock_type.stealable: return False # Can't steal locks of a different type for l in self.lock_info(): if not hasattr(l['type'], '__name__') or \ l['type'].__name__ != lock_type.__name__: return False # The lock type is stealable, and the object is not marked as # non-stelaable, so return True if not INonStealableLock.providedBy(self.context): return True # Lock type is stealable, object is not stealable, but return True # anyway if we can safely unlock this object (e.g. we are the owner) return self.can_safely_unlock(lock_type)
def reply(self): lockable = ILockable(self.context) if lockable.can_safely_unlock(): lockable.unlock() if INonStealableLock.providedBy(self.context): noLongerProvides(self.context, INonStealableLock) # Disable CSRF protection if "IDisableCSRFProtection" in dir(plone.protect.interfaces): alsoProvides(self.request, plone.protect.interfaces.IDisableCSRFProtection) return lock_info(self.context)
def stealable(self, lock_type=STEALABLE_LOCK): # If the lock type is not stealable ever, return False if not lock_type.stealable: return False # Can't steal locks of a different type for l in self.lock_info(): if not hasattr(l["type"], "__name__") or l["type"].__name__ != lock_type.__name__: return False # The lock type is stealable, and the object is not marked as # non-stelaable, so return True if not INonStealableLock.providedBy(self.context): return True # Lock type is stealable, object is not stealable, but return True # anyway if we can safely unlock this object (e.g. we are the owner) return self.can_safely_unlock(lock_type)
def stealable(self, lock_type=STEALABLE_LOCK): # If the lock type is not stealable ever, return False if not lock_type.stealable: return False # Can't steal locks of a different type for l in self.lock_info(): if not hasattr(l['type'], '__name__') or \ l['type'].__name__ != lock_type.__name__: return False # The lock type is stealable, and the object is not marked as # non-stelaable, so return True if not INonStealableLock.providedBy(self.context): return True # Lock type is stealable, object is not stealable, but return True # anyway if we can safely unlock this object (e.g. we are the owner) return self.can_safely_unlock(lock_type)
def reply(self): lockable = ILockable(self.context, None) if lockable is None: return lock_info(self.context) data = json_body(self.request) # Remove lock by the same user or steal it if lockable.can_safely_unlock() or data.get("force"): lockable.unlock() if INonStealableLock.providedBy(self.context): noLongerProvides(self.context, INonStealableLock) # Disable CSRF protection if "IDisableCSRFProtection" in dir(plone.protect.interfaces): alsoProvides(self.request, plone.protect.interfaces.IDisableCSRFProtection) return lock_info(self.context)
def test_lock_object_non_stealable(self): response = self.api_session.post("/@lock", json={"stealable": False}) transaction.commit() self.assertEqual(response.status_code, 200) self.assertTrue(INonStealableLock.providedBy(self.doc))