Skip to content

Commit

Permalink
fix updating mtime when changing RR entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
petschki committed Sep 23, 2023
1 parent 93a5f4a commit 25dba45
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Products/CMFPlone/resources/browser/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def _cache_attr_name(self):
hashtool.update(self._user_local_roles().encode("utf8"))
if not getattr(self, "registry", None):
self.registry = getUtility(IRegistry)
mtime = getattr(self.registry, _RESOURCE_REGISTRY_MTIME, None)
if mtime is not None:
hashtool.update(str(mtime).encode("utf8"))
mtime = getattr(self.registry, _RESOURCE_REGISTRY_MTIME, None)
if mtime is not None:
hashtool.update(str(mtime).encode("utf8"))
return f"_v_rendered_cache_{hashtool.hexdigest()}"

@property
Expand Down
43 changes: 42 additions & 1 deletion Products/CMFPlone/tests/testResourceRegistries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from plone.testing.zope import Browser
from Products.CMFPlone.resources import add_bundle_on_request
from Products.CMFPlone.resources import remove_bundle_on_request
from Products.CMFPlone.resources.browser.resource import _RESOURCE_REGISTRY_MTIME
from Products.CMFPlone.resources.browser.resource import ScriptsView
from Products.CMFPlone.resources.browser.resource import StylesView
from Products.CMFPlone.tests import PloneTestCase
Expand Down Expand Up @@ -396,7 +397,6 @@ def test_styles_on_portal_type(self):
self.assertIn("http://test4.foo/test.css", results)
self.assertIn("http://test3.foo/test.css", results)


def test_scripts_authenticated(self):
scripts = ScriptsView(self.layer["portal"], self.layer["request"], None)
scripts.update()
Expand Down Expand Up @@ -455,6 +455,7 @@ def test_scripts_switching_roles(self):
class TestRRControlPanel(PloneTestCase.PloneTestCase):
def setUp(self):
self.portal = self.layer["portal"]
self.registry = getUtility(IRegistry)
self.app = self.layer["app"]
self.browser = Browser(self.app)
self.browser.handleErrors = False
Expand Down Expand Up @@ -504,3 +505,43 @@ def test_update_resource(self):
'<h2 class="accordion-header" id="heading-new-resource-name">',
self.browser.contents,
)

def test_update_registry_mtime(self):
mtime = str(getattr(self.registry, _RESOURCE_REGISTRY_MTIME, ""))

add_form = self.browser.getForm(index=5)
add_form.getControl(name="name").value = "my-resource"
add_form.getControl(name="jscompilation").value = "++resource++my.resource.js"
add_form.getControl(name="enabled").value = "checked"
add_form.getControl("add").click()

# check for updates ScriptsViewlet
self.assertIn(
'++resource++my.resource.js"></script>',
self.browser.contents,
)

# new modification time has to be larger
self.assertTrue(
str(getattr(self.registry, _RESOURCE_REGISTRY_MTIME, ""))
> mtime
)

mtime = str(getattr(self.registry, _RESOURCE_REGISTRY_MTIME, ""))

# new resource form has index=3
my_resource_form = self.browser.getForm(index=3)
my_resource_form.getControl(name="enabled").value = ""
my_resource_form.getControl("update").click()

# check for updated ScriptsViewlet with disabled resource
self.assertNotIn(
'++resource++my.resource.js"></script>',
self.browser.contents,
)

# new modification time has to be larger
self.assertTrue(
str(getattr(self.registry, _RESOURCE_REGISTRY_MTIME, ""))
> mtime
)

0 comments on commit 25dba45

Please sign in to comment.