Skip to content

Commit

Permalink
Merge pull request #122 from plone/locking-etag-token
Browse files Browse the repository at this point in the history
can't save page with listing block and standard caching rules (due to etag not showing lock)
  • Loading branch information
davisagli authored Oct 24, 2023
2 parents 74f8bee + aa71625 commit 99718e8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions news/122.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `locked` component of ETag to discriminate between different locks. @JeffersonBledsoe, @davisagli
16 changes: 10 additions & 6 deletions plone/app/caching/operations/etags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions plone/app/caching/tests/test_etags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 99718e8

Please sign in to comment.