Skip to content

Commit

Permalink
Merge pull request #636 from ZeitOnline/fix/form-error
Browse files Browse the repository at this point in the history
ZO-4801: Display request errors that occur in JS forms
  • Loading branch information
stollero authored Feb 27, 2024
2 parents 5a0570c + 2175e1d commit 6925848
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/docs/changelog/ZO-4801-error.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ZO-4801: Display request errors that occur in JS forms (toggle: `inlineform_alert_error`)
1 change: 1 addition & 0 deletions core/src/zeit/cms/browser/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ zeit.cms.with_lock = function(callable) {
});
d.addErrback(function(error) {
zeit.cms.log_error(error);
return error;
});
d.addBoth(function(result_or_error) {
zeit.cms.request_lock.release();
Expand Down
8 changes: 3 additions & 5 deletions core/src/zeit/cms/browser/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ zeit.cms.SubPageForm = gocept.Class.extend({
d.addCallbacks(
MochiKit.Base.bind(self.replace_content, self),
function(error) {
logError(error.req.status, error.req.statusText);
var parser = new DOMParser();
var doc = parser.parseFromString(
error.req.responseText, "text/xml");
document.firstChild.nextSibling.nextSibling.innerHTML = doc.firstChild.nextSibling.innerHTML;
if (window.feature_toggles.inlineform_alert_error) {
alert('Ein Systemfehler ist aufgetreten: ' + error.req.responseText);
}
});
d.addCallback(MochiKit.Base.bind(self.process_post_result, self));
d.addCallback(function(result) {
Expand Down
1 change: 1 addition & 0 deletions core/src/zeit/cms/browser/main_template.pt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<script type="text/javascript" tal:content="string:
var application_url = '${request/getApplicationURL}';
var context_url = '${context/@@absolute_url}';
var feature_toggles = ${context/@@standard_macros/toggles_as_json};
"/>
<tal:comment condition="nothing">
Make sure that application_url and context_url are available
Expand Down
6 changes: 6 additions & 0 deletions core/src/zeit/cms/browser/standardmacros.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import importlib.metadata
import json

import zope.app.appsetup.product
import zope.app.basicskin.standardmacros
import zope.component
import zope.location.interfaces
import zope.security.proxy

from zeit.cms.content.sources import FEATURE_TOGGLES
import zeit.cms.browser
import zeit.cms.browser.interfaces
import zeit.cms.browser.resources
Expand Down Expand Up @@ -68,3 +70,7 @@ def vivi_version(self):
return importlib.metadata.version('vivi.core')
except Exception:
return 'version not found'

@property
def toggles_as_json(self):
return json.dumps(FEATURE_TOGGLES.factory._values())
18 changes: 18 additions & 0 deletions core/src/zeit/cms/browser/tests/test_standardmacros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from zeit.cms.content.sources import FEATURE_TOGGLES
import zeit.cms.testing


class MainTemplateTest(zeit.cms.testing.ZeitCmsBrowserTestCase):
def test_passes_feature_toggles_to_javascript(self):
b = self.browser
b.open('/repository')
self.assertEllipsis(
'...var feature_toggles = {..."article_agencies": true, ...};...', b.contents
)

# Test overrides also work
FEATURE_TOGGLES.unset('article_agencies')
b.open('/repository')
self.assertEllipsis(
'...var feature_toggles = {..."article_agencies": false, ...};...', b.contents
)
1 change: 1 addition & 0 deletions core/src/zeit/cms/content/feature-toggle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<author_lookup_in_hdok>true</author_lookup_in_hdok>
<content_caching>true</content_caching>
<embed_cmp_thirdparty>true</embed_cmp_thirdparty>
<inlineform_alert_error>true</inlineform_alert_error>
<breakingnews_with_channel>true</breakingnews_with_channel>
<push_new_articles_ua_author_tag>true</push_new_articles_ua_author_tag>
<reference_index>true</reference_index>
Expand Down
9 changes: 9 additions & 0 deletions core/src/zeit/cms/content/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,15 @@ def override(self, value, *names):
def _overrides(self):
return {}

def getValues(self, context):
return [k for k, v in self._values().items() if v]

def _values(self):
tree = self._get_tree()
result = {node.tag: bool(node) for node in tree.xpath('//*') if not node.getchildren()}
result.update(self._overrides())
return result


FEATURE_TOGGLES = FeatureToggleSource()(None)

Expand Down

0 comments on commit 6925848

Please sign in to comment.