Skip to content

Commit

Permalink
- Fix some broken ZMI pages due to the changed default content type (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Dec 17, 2022
1 parent 9759d9b commit 88aac86
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ https://zope.readthedocs.io/en/2.13/CHANGES.html
4.8.5 (unreleased)
------------------

- Fix some broken ZMI pages due to the changed default content type
from PR https://github.com/zopefoundation/Zope/pull/1075
(`#1078 <https://github.com/zopefoundation/Zope/issues/1078>`_)

- Update dependencies to the latest releases for each supported Python version.


Expand Down
9 changes: 9 additions & 0 deletions src/App/special_dtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ def _exec(self, bound_data, args, kw):

security = getSecurityManager()
security.addContext(self)

# Set a content type to override the publisher default "text/plain"
# This class is only used in the Zope ZMI so it's safe to assume
# that it is rendering HTML.
if 'REQUEST' in bound_data:
response = bound_data['REQUEST'].RESPONSE
if not response.getHeader('Content-Type'):
response.setHeader('Content-Type', 'text/html')

try:
value = self.ZDocumentTemplate_beforeRender(ns, _marker)
if value is _marker:
Expand Down
25 changes: 25 additions & 0 deletions src/App/tests/testManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,28 @@ def test_Tabs_tabs_path_length(self):
self.app.REQUEST.traverse(path)

self.assertEqual(self.folder.tabs_path_length(self.app.REQUEST), 2)

def test_Tabs_content_type(self):
req = self.app.REQUEST

self.folder.manage_tabs(req)
self.assertIn('text/html', req.RESPONSE.getHeader('Content-Type'))


class TestManagePages(Testing.ZopeTestCase.ZopeTestCase):

def setUp(self):
super().setUp()
uf = self.folder.acl_users
uf.userFolderAddUser('mgr', 'foo', ['Manager'], [])
self.login('mgr')

def tearDown(self):
self.logout()
super().tearDown()

def test_manage_content_type(self):
req = self.app.REQUEST

self.folder.manage(req)
self.assertIn('text/html', req.RESPONSE.getHeader('Content-Type'))

0 comments on commit 88aac86

Please sign in to comment.