From f4bb9bc9762c2fa99d3f72126eb0efc9ace1afa4 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 31 Jan 2017 09:25:04 +0100 Subject: [PATCH] [FIX] im_livechat,web: partial revert of 7f8fe1076660ab Proxy.load is required by the livechat when it is embedded in an external page, so that it is able to get the static xml files (with the correct base_url). opw-706497 --- addons/im_livechat/static/src/js/im_livechat.js | 17 ++++++++--------- addons/web/controllers/main.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/addons/im_livechat/static/src/js/im_livechat.js b/addons/im_livechat/static/src/js/im_livechat.js index 446717b1b7f..df9cd99b7d7 100644 --- a/addons/im_livechat/static/src/js/im_livechat.js +++ b/addons/im_livechat/static/src/js/im_livechat.js @@ -82,16 +82,15 @@ var LivechatButton = Widget.extend({ }, load_qweb_template: function(){ - return $.when( - $.get('/mail/static/src/xml/chat_window.xml'), - $.get('/mail/static/src/xml/thread.xml'), - $.get('/im_livechat/static/src/xml/im_livechat.xml') - ).then(function (chat_window, mail_thread, livechat) { - // results are triplets of [dom: XMLDocument, status: String, xhr: jqXHR] - QWeb.add_template(chat_window[0]); - QWeb.add_template(mail_thread[0]); - QWeb.add_template(livechat[0]); + var xml_files = ['/mail/static/src/xml/chat_window.xml', + '/mail/static/src/xml/thread.xml', + '/im_livechat/static/src/xml/im_livechat.xml']; + var defs = _.map(xml_files, function (tmpl) { + return session.rpc('/web/proxy/load', {path: tmpl}).then(function (xml) { + QWeb.add_template(xml); + }); }); + return $.when.apply($, defs); }, open_chat: _.debounce(function () { diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 3e6b19adf11..496f234f7e0 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -586,6 +586,22 @@ class WebClient(http.Controller): class Proxy(http.Controller): + @http.route('/web/proxy/load', type='json', auth="none") + def load(self, path): + """ Proxies an HTTP request through a JSON request. + + It is strongly recommended to not request binary files through this, + as the result will be a binary data blob as well. + + :param path: actual request path + :return: file content + """ + from werkzeug.test import Client + from werkzeug.wrappers import BaseResponse + + base_url = request.httprequest.base_url + return Client(request.httprequest.app, BaseResponse).get(path, base_url=base_url).data + @http.route('/web/proxy/post/', type='http', auth='user', methods=['GET']) def post(self, path): """Effectively execute a POST request that was hooked through user login"""