Skip to content

Commit

Permalink
Merge pull request #184 from plone/maurits/issue-183-save-advanced-co…
Browse files Browse the repository at this point in the history
…ntrolpanel-wrongtype

Call processInputs when available, fixing WrongType
  • Loading branch information
mauritsvanrees authored Jun 11, 2020
2 parents 79f1df0 + a360731 commit fdbb576
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
4 changes: 4 additions & 0 deletions news/183.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix various ``WrongType`` exceptions when saving the control panel.
This was introduces by the ``processInputs`` change in version 4.0.5.
See `issue 183 <https://github.com/plone/plone.app.theming/issues/183>`_.
[maurits]
4 changes: 2 additions & 2 deletions src/plone/app/theming/browser/controlpanel.pt
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
<div
tal:define="error errors/hostnameBlacklist | nothing;
hostnameBlacklist view/theme_settings/hostnameBlacklist | python:[];
hostnameBlacklist python: view.hostname_blacklist or hostnameBlacklist"
hostnameBlacklist python:request.get('hostnameBlacklist', hostnameBlacklist)"
tal:attributes="class python:'field error' if error else 'field'">

<label for="hostnameBlacklist" i18n:translate="label_hostname_blacklist">Unthemed host names</label>
Expand All @@ -481,7 +481,7 @@
id="hostnameBlacklist"
rows="5"
cols="50"
tal:content="python: '\n'.join(hostnameBlacklist)"
tal:content="python:'\n'.join(hostnameBlacklist)"
></textarea>

</div>
Expand Down
21 changes: 14 additions & 7 deletions src/plone/app/theming/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
import zipfile


try:
# Zope 4
from Products.Five.browser.decode import processInputs
except ImportError:
# Zope 5
processInputs = None


logger = logging.getLogger('plone.app.theming')


Expand All @@ -52,11 +60,6 @@ def site_url(self):
"""
return getSite().absolute_url()

@property
def hostname_blacklist(self):
hostname_blacklist = self.request.get('hostnameBlacklist', [])
return [host.decode() for host in hostname_blacklist]

def __call__(self):
self.pskin = getToolByName(self.context, 'portal_skins')
if self.update():
Expand Down Expand Up @@ -111,6 +114,8 @@ def set_ext_links_open_new_window(self, value):

def update(self):
# XXX: complexity too high: refactoring needed
if processInputs is not None:
processInputs(self.request)
self._setup()
self.errors = {}
form = self.request.form
Expand Down Expand Up @@ -170,6 +175,8 @@ def update(self):
prefix = form.get('absolutePrefix', None)
doctype = str(form.get('doctype', ""))

hostnameBlacklist = form.get('hostnameBlacklist', [])

parameterExpressions = {}
parameterExpressionsList = form.get('parameterExpressions', [])

Expand Down Expand Up @@ -203,10 +210,10 @@ def update(self):
self.theme_settings.rules = rules
self.theme_settings.absolutePrefix = prefix
self.theme_settings.parameterExpressions = parameterExpressions
self.theme_settings.hostnameBlacklist = self.hostname_blacklist
self.theme_settings.hostnameBlacklist = hostnameBlacklist
if custom_css != self.theme_settings.custom_css:
self.theme_settings.custom_css_timestamp = datetime.now()
self.theme_settings.custom_css = str(custom_css)
self.theme_settings.custom_css = custom_css
self.theme_settings.doctype = doctype

# Theme base settings
Expand Down
13 changes: 13 additions & 0 deletions src/plone/app/theming/browser/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
import six


try:
# Zope 4
from Products.Five.browser.decode import processInputs
except ImportError:
# Zope 5
processInputs = None


class ThemeMapper(BrowserView):

theme_error_template = ViewPageTemplateFile("theme-error.pt")
Expand All @@ -60,6 +68,8 @@ def development(self):

def setup(self):
self.request.response.setHeader('X-Theme-Disabled', '1')
if processInputs is not None:
processInputs(self.request)

self.resourceDirectory = self.context
self.theme = getThemeFromResourceDirectory(self.context)
Expand Down Expand Up @@ -216,6 +226,9 @@ def getFrame(self):
- a query string parameter ``title`` can be set to give a new page
title
"""
if processInputs is not None:
processInputs(self.request)

path = self.request.form.get('path', '/')
theme = self.request.form.get('theme', 'off')
links = self.request.form.get('links', None)
Expand Down
17 changes: 8 additions & 9 deletions src/plone/app/theming/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<gs:upgradeStep
title="Update registry"
source="*"
destination="1000"
handler=".upgrade.update_registry"
sortkey="1"
profile="plone.app.theming:default"
/>

<gs:upgradeStep
title="Combine Theming control panels"
source="1000"
Expand All @@ -44,6 +35,14 @@
profile="plone.app.theming:default"
/>

<gs:upgradeStep
title="Update registry"
source="1001"
destination="1002"
handler=".upgrade.update_registry"
profile="plone.app.theming:default"
/>

<!-- Transform order 8850 - apply theme transform -->
<adapter
name="plone.app.theming.transform"
Expand Down
2 changes: 1 addition & 1 deletion src/plone/app/theming/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<metadata>
<version>1001</version>
<version>1002</version>
<dependencies>
<dependency>profile-plone.app.registry:default</dependency>
</dependencies>
Expand Down
11 changes: 10 additions & 1 deletion src/plone/app/theming/tests/test_controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def goto_controlpanel(self):
self.portal.absolute_url() + '/@@theming-controlpanel'
)

def test_save_advanced(self):
# Simply saving the advanced panel without changes could already give a WrongType error.
# See for example https://github.com/plone/plone.app.theming/issues/179
# but there are more.
self.browser.handleErrors = False
self.goto_controlpanel()
button = self.browser.getControl(name="form.button.AdvancedSave")
button.click()

def test_create_theme(self):
pass
# self.goto_controlpanel()
Expand Down Expand Up @@ -75,7 +84,7 @@ def test_upload_theme_file_withdata(self):
Content-Type: image/png
---blah---
---blah---
""",
# Bug in testbrowser prevents this working
# content_type='multipart/form-data; boundary=---blah---'
Expand Down

0 comments on commit fdbb576

Please sign in to comment.