From c13c9e0b5c6ff8a8ae030ff2467d4675fb6197b8 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Wed, 8 Nov 2017 12:42:55 +0100 Subject: [PATCH] [FIX] web: invalid domain in DomainSelector A domain could contain the key `parent` (in an embedded subview), like: domain="[('display_name', '=', parent.display_name)]") This is currently not handled by the DomainSelector. This will probably be handled in a future version but for this stable version, this case that triggered an error is now catched and an error message is displayed in the widget. This was causing a traceback when opening a domain with `parent` in the edition of a subview with Studio. --- .../static/src/js/widgets/domain_selector.js | 21 ++++++++++++++++++- .../tests/widgets/domain_selector_tests.js | 19 +++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/widgets/domain_selector.js b/addons/web/static/src/js/widgets/domain_selector.js index 782128994db..0619cf613c6 100644 --- a/addons/web/static/src/js/widgets/domain_selector.js +++ b/addons/web/static/src/js/widgets/domain_selector.js @@ -179,7 +179,16 @@ var DomainTree = DomainNode.extend({ */ init: function (parent, model, domain, options) { this._super.apply(this, arguments); - this._initialize(Domain.prototype.stringToArray(domain)); + try { + domain = Domain.prototype.stringToArray(domain); + } catch (err) { + // TODO: domain could contain `parent` for example, which is + // currently not handled by the DomainSelector + this.invalidDomain = true; + this.children = []; + return; + } + this._initialize(domain); }, /** * @see DomainNode.start @@ -443,6 +452,16 @@ var DomainSelector = DomainTree.extend({ domain_changed: "_onDomainChange", }), + start: function () { + var self = this; + return this._super.apply(this, arguments).then(function () { + if (self.invalidDomain) { + var msg = _t("This domain is not supported."); + self.$el.html(msg); + } + }); + }, + //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- diff --git a/addons/web/static/tests/widgets/domain_selector_tests.js b/addons/web/static/tests/widgets/domain_selector_tests.js index 55ddc971642..aca017e831c 100644 --- a/addons/web/static/tests/widgets/domain_selector_tests.js +++ b/addons/web/static/tests/widgets/domain_selector_tests.js @@ -194,6 +194,25 @@ QUnit.module('DomainSelector', { domainSelector.destroy(); }); + + QUnit.test("editing a domain with `parent` key", function (assert) { + assert.expect(1); + + var $target = $("#qunit-fixture"); + + // Create the domain selector and its mock environment + var domainSelector = new DomainSelector(null, "product", "[['name','=',parent.foo]]", { + debugMode: true, + readonly: false, + }); + testUtils.addMockEnvironment(domainSelector, {data: this.data}); + domainSelector.appendTo($target); + + assert.strictEqual(domainSelector.$el.text(), "This domain is not supported.", + "an error message should be displayed because of the `parent` key"); + + domainSelector.destroy(); + }); }); }); });