diff options
| author | qsm-odoo <qsm@odoo.com> | 2018-09-28 14:50:18 +0200 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2018-09-30 19:55:17 +0200 |
| commit | 55131b8f5becdd3d4776f4c3e7e4288a0b185706 (patch) | |
| tree | 4eca54d0cd14a2180227ad2b155e3380d37fb9a6 /addons/web_editor | |
| parent | feae553b98c88282695c77382f4a52c78b3f8f70 (diff) | |
[REF] website, *: add automatic context for call_kw rpc
* web_editor, website_blog, website_crm_partner_assign, website_links,
website_livechat, website_mail_channel, website_mass_mailing,
website_slides
Calling a model's method thanks to an RPC will now always send the
web_editor context automatically, making sure the method gets the
website_id all the time, removing the need to guess the current website
(now the get_current_website method uses the context website_id if any).
Note: other routes already have the website_id via request.env.context
if they correctly set website=True (this commit also adds website=True
for scss files customization routes).
Diffstat (limited to 'addons/web_editor')
6 files changed, 34 insertions, 13 deletions
diff --git a/addons/web_editor/controllers/main.py b/addons/web_editor/controllers/main.py index 13a633b5951..2eba6fff81e 100644 --- a/addons/web_editor/controllers/main.py +++ b/addons/web_editor/controllers/main.py @@ -140,7 +140,7 @@ class Web_Editor(http.Controller): #------------------------------------------------------ # add attachment (images or link) #------------------------------------------------------ - @http.route('/web_editor/attachment/add', type='http', auth='user', methods=['POST']) + @http.route('/web_editor/attachment/add', type='http', auth='user', methods=['POST'], website=True) def attach(self, upload=None, url=None, disable_optimization=None, filters=None, **kwargs): # the upload argument doesn't allow us to access the files if more than # one file is uploaded, as upload references the first file @@ -215,7 +215,7 @@ class Web_Editor(http.Controller): #------------------------------------------------------ # remove attachment (images or link) #------------------------------------------------------ - @http.route('/web_editor/attachment/remove', type='json', auth='user') + @http.route('/web_editor/attachment/remove', type='json', auth='user', website=True) def remove(self, ids, **kwargs): """ Removes a web-based image attachment if it is used by no view (template) @@ -249,7 +249,7 @@ class Web_Editor(http.Controller): ## This route is used from CropImageDialog to get image info. ## It is used to display the original image when we crop a previously ## cropped image - @http.route('/web_editor/get_image_info', type='json', auth='user') + @http.route('/web_editor/get_image_info', type='json', auth='user', website=True) def get_image_info(self, image_id=None, xml_id=None): if xml_id: record = request.env.ref(xml_id) @@ -390,7 +390,7 @@ class Web_Editor(http.Controller): ## @param url - the original url of the scss file which has to be modified ## @param bundle_xmlid - the xmlid of the bundle in which the scss file addition can be found ## @param content - the new content of the scss file - @http.route("/web_editor/save_scss", type="json", auth="user") + @http.route("/web_editor/save_scss", type="json", auth="user", website=True) def save_scss(self, url, bundle_xmlid, content): IrAttachment = request.env["ir.attachment"] @@ -444,7 +444,7 @@ class Web_Editor(http.Controller): ## The reset_scss route is in charge of reverting all the changes that were done to a scss file. ## @param url - the original URL of the scss file to reset ## @param bundle_xmlid - the xmlid of the bundle in which the scss file addition can be found - @http.route("/web_editor/reset_scss", type="json", auth="user") + @http.route("/web_editor/reset_scss", type="json", auth="user", website=True) def reset_scss(self, url, bundle_xmlid): custom_url = self._make_custom_scss_file_url(url, bundle_xmlid) diff --git a/addons/web_editor/static/src/js/content/body_manager.js b/addons/web_editor/static/src/js/content/body_manager.js index 2291aa1d4db..85ace262fc5 100644 --- a/addons/web_editor/static/src/js/content/body_manager.js +++ b/addons/web_editor/static/src/js/content/body_manager.js @@ -1,6 +1,7 @@ odoo.define('web_editor.BodyManager', function (require) { 'use strict'; +var weContext = require('web_editor.context'); var rootWidget = require('web_editor.root_widget'); var ServiceProviderMixin = require('web.ServiceProviderMixin'); var session = require('web.session'); @@ -28,6 +29,27 @@ var BodyManager = rootWidget.RootWidget.extend(ServiceProviderMixin, { session.is_bound ); }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Automatically add the web_editor context. + * + * @override + */ + _call_service: function (event) { + if (event.data.service === 'ajax' && event.data.method === 'rpc') { + var route = event.data.args[0]; + if (_.str.startsWith(route, '/web/dataset/call_kw/')) { + var params = event.data.args[1]; + params.kwargs.context = _.extend({}, weContext.get(), params.kwargs.context || {}); + params.kwargs.context = JSON.parse(JSON.stringify(params.kwargs.context)); + } + } + return ServiceProviderMixin._call_service.apply(this, arguments); + }, }); return BodyManager; }); diff --git a/addons/web_editor/static/src/js/editor/rte.js b/addons/web_editor/static/src/js/editor/rte.js index 11001cc7a06..8719779c079 100644 --- a/addons/web_editor/static/src/js/editor/rte.js +++ b/addons/web_editor/static/src/js/editor/rte.js @@ -573,8 +573,8 @@ var RTEWidget = Widget.extend({ $el.data('oe-id'), this._getEscapedElement($el).prop('outerHTML'), $el.data('oe-xpath') || null, - withLang ? context : _.omit(context, 'lang') ], + context: withLang ? context : _.extend({}, context, {lang: undefined}), }); }, diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index ab82d34a23b..aed0ca91a66 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -1236,7 +1236,6 @@ registry.many2one = SnippetOption.extend({ kwargs: { order: [{name: 'name', asc: false}], limit: 5, - context: weContext.get(), }, }).then(function (result) { self.$search.siblings().remove(); @@ -1275,7 +1274,6 @@ registry.many2one = SnippetOption.extend({ args: [[self.ID]], kwargs: { options: options, - context: weContext.get(), }, }).then(function (html) { $node.html(html); diff --git a/addons/web_editor/static/src/js/editor/translator.js b/addons/web_editor/static/src/js/editor/translator.js index cf9b0a0b085..c6cadb40562 100644 --- a/addons/web_editor/static/src/js/editor/translator.js +++ b/addons/web_editor/static/src/js/editor/translator.js @@ -34,12 +34,12 @@ var RTETranslatorWidget = rte.Class.extend({ method: 'save_html', args: [ [+$el.data('oe-translation-id')], - this._getEscapedElement($el).html(), - context || weContext.get() + this._getEscapedElement($el).html() ], + context: context, }).fail(function (error) { - Dialog.alert(null, error.data.message); - }); + Dialog.alert(null, error.data.message); + }); } return this._super($el, context, withLang === undefined ? true : withLang); }, diff --git a/addons/web_editor/static/src/js/widgets/ace.js b/addons/web_editor/static/src/js/widgets/ace.js index c6cbb43295f..bd5b4a9c47a 100644 --- a/addons/web_editor/static/src/js/widgets/ace.js +++ b/addons/web_editor/static/src/js/widgets/ace.js @@ -593,7 +593,8 @@ var ViewEditor = Widget.extend({ this._rpc({ model: 'ir.ui.view', method: 'write', - args: [[session.id], {arch: session.text}, _.extend(weContext.get(), {lang: null})], + args: [[session.id], {arch: session.text}], + context: _.extend({}, weContext.get(), {lang: undefined}), }).then(function () { self._toggleDirtyInfo(session.id, 'xml', false); def.resolve(); |
