Skip to content
Snippets Groups Projects
Commit c13c9e0b authored by Martin Geubelle's avatar Martin Geubelle
Browse files

[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.
parent 9f0bc837
No related branches found
No related tags found
No related merge requests found
......@@ -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
//--------------------------------------------------------------------------
......
......@@ -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();
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment