diff --git a/news/122.bugfix b/news/122.bugfix new file mode 100644 index 0000000..1b2c10f --- /dev/null +++ b/news/122.bugfix @@ -0,0 +1 @@ +Fix `locked` component of ETag to discriminate between different locks. @JeffersonBledsoe, @davisagli diff --git a/plone/app/caching/operations/etags.py b/plone/app/caching/operations/etags.py index 20f1783..2138ba0 100644 --- a/plone/app/caching/operations/etags.py +++ b/plone/app/caching/operations/etags.py @@ -163,12 +163,16 @@ def __init__(self, published, request): def __call__(self): context = getContext(self.published) - context_state = queryMultiAdapter( - (context, self.request), name="plone_context_state" - ) - if context_state is None: - return - return "1" if context_state.is_locked() else "0" + lock = queryMultiAdapter((context, self.request), name="plone_lock_info") + + if not lock: + return "0" + + lock_info = lock.lock_info() + if not lock_info: + return "0" + + return lock_info["token"] @implementer(IETagValue) diff --git a/plone/app/caching/tests/test_etags.py b/plone/app/caching/tests/test_etags.py index 83e281d..59c29c8 100644 --- a/plone/app/caching/tests/test_etags.py +++ b/plone/app/caching/tests/test_etags.py @@ -281,14 +281,14 @@ def test_ObjectLocked_true(self): @implementer(Interface) @adapter(DummyContext, Interface) - class DummyContextState: + class DummyLockInfo: def __init__(self, context, request): pass - def is_locked(self): - return True + def lock_info(self): + return {"token": "lock-token-1234"} - provideAdapter(DummyContextState, name="plone_context_state") + provideAdapter(DummyLockInfo, name="plone_lock_info") environ = {"SERVER_NAME": "example.com", "SERVER_PORT": "80"} response = HTTPResponse() @@ -297,21 +297,21 @@ def is_locked(self): etag = ObjectLocked(published, request) - self.assertEqual("1", etag()) + self.assertEqual("lock-token-1234", etag()) def test_ObjectLocked_false(self): from plone.app.caching.operations.etags import ObjectLocked @implementer(Interface) @adapter(DummyContext, Interface) - class DummyContextState: + class DummyLockInfo: def __init__(self, context, request): pass - def is_locked(self): - return False + def lock_info(self): + return None - provideAdapter(DummyContextState, name="plone_context_state") + provideAdapter(DummyLockInfo, name="plone_lock_info") environ = {"SERVER_NAME": "example.com", "SERVER_PORT": "80"} response = HTTPResponse()