From d7939282e906cd547db837770f139a6ab02f19ff Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Thu, 11 Aug 2016 14:26:33 +0200 Subject: [PATCH] [FIX] mass_mailing: avoid too long URIs by blacklisting fields in editor call The call to the web_editor is made through an iframe with some get parameters. While not really a problem in itself, this has the disadvantage of generating long URIs. In some case, since all the fields in the views are included as a GET parameter, URIs can be generated that go up to several thousand characters. Most servers will return a 414 for such URIs, preventing the edition of the mail template in the view. To avoid this problem, this commit extends the 'html_frame' widget and blacklist 2 fields that can get too long once encoded. Ideally, it would probably be better to stop sending all the fields and simply add the *needed* fields one by one, but since it's difficult to know exactly what fields might be needed and this is stable, I'm gonna go with this 'workaround' but conservative fix. opw-685646 --- .../mass_mailing/static/src/js/mass_mailing.js | 18 ++++++++++++++++++ addons/web_editor/static/src/js/backend.js | 11 +++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/addons/mass_mailing/static/src/js/mass_mailing.js b/addons/mass_mailing/static/src/js/mass_mailing.js index 3785cf87070..e2bcb8a09ad 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing.js +++ b/addons/mass_mailing/static/src/js/mass_mailing.js @@ -1,6 +1,7 @@ odoo.define('mass_mailing.mass_mailing', function (require) { var core = require('web.core'); +var FieldTextHtml = require('web_editor.backend').FieldTextHtml; var KanbanRecord = require('web_kanban.Record'); var KanbanView = require('web_kanban.KanbanView'); @@ -25,4 +26,21 @@ KanbanView.include({ }, }); +FieldTextHtml.include({ + get_datarecord: function() { + /* Avoid extremely long URIs by whitelisting fields in the datarecord + that get set as a get parameter */ + var datarecord = this._super(); + if (this.view.model === 'mail.mass_mailing') { + // these fields can potentially get very long, let's remove them + var blacklist = ['mailing_domain', 'contact_list_ids']; + for (var k in blacklist) { + delete datarecord[blacklist[k]]; + } + delete datarecord[this.name]; + } + return datarecord; + }, +}); + }); diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index fa962cfd75f..de1d937d7ac 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -220,9 +220,12 @@ var FieldTextHtml = widget.extend({ this.$translate = $(); return def; }, + get_datarecord: function() { + return this.view.get_fields_values(); + }, get_url: function (_attr) { var src = this.options.editor_url || "/web_editor/field/html"; - var datarecord = this.view.get_fields_values(); + var datarecord = this.get_datarecord(); var attr = { 'model': this.view.model, @@ -269,7 +272,6 @@ var FieldTextHtml = widget.extend({ delete datarecord[this.name]; src += "&datarecord="+ encodeURIComponent(JSON.stringify(datarecord)); - return src; }, initialize_content: function() { @@ -384,4 +386,9 @@ core.form_widget_registry .add('html', FieldTextHtmlSimple) .add('html_frame', FieldTextHtml); +return { + FieldTextHtmlSimple: FieldTextHtmlSimple, + FieldTextHtml: FieldTextHtml, +}; + });