From fadd3119456b9429aeb336802a4a2b41d897ac17 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 21 Nov 2012 11:19:17 +0100 Subject: [PATCH] [FIX] mail: remove ugly hack for context filtering that wreaks havoc in contexts This hacks makes a mess and works with a whitelist that completely breaks the generic context passing mechanism. Replaced by specific guard through default_get overrides for the models that are sensitive to default value leaks via context. E.g. mail.message is sensitive to leaked default_type context keys that are meant for other models, such as those passed by the Invoices menus. bzr revid: odo@openerp.com-20121121101917-izeu4c493un86udf --- addons/mail/mail_message.py | 6 ++++++ addons/mail/static/src/js/mail.js | 33 ------------------------------- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index e7288a46853..ba6d101541c 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -59,6 +59,12 @@ class mail_message(osv.Model): _message_record_name_length = 18 _message_read_more_limit = 1024 + def default_get(self, cr, uid, fields, context=None): + # protection for `default_type` values leaking from menu action context (e.g. for invoices) + if context and context.get('default_type') and context.get('default_type') not in self._columns['type'].selection: + context = dict(context, default_type=None) + return super(mail_message, self).default_get(cr, uid, fields, context=context) + def _shorten_name(self, name): if len(name) <= (self._message_record_name_length + 3): return name diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 040b83e8f33..44bb4e9ae09 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -7,39 +7,6 @@ openerp.mail = function (session) { openerp_mail_followers(session, mail); // import mail_followers.js openerp_FieldMany2ManyTagsEmail(session); // import manyy2many_tags_email.js - /** - * ------------------------------------------------------------ - * FormView - * ------------------------------------------------------------ - * - * Override of formview do_action method, to catch all return action about - * mail.compose.message. The purpose is to bind 'Send by e-mail' buttons. - */ - - session.web.FormView = session.web.FormView.extend({ - do_action: function (action) { - if (action.res_model == 'mail.compose.message') { - /* hack for stop context propagation of wrong value - * delete this hack when a global method to clean context is create - */ - var context_keys = ['default_template_id', 'default_composition_mode', - 'default_use_template', 'default_partner_ids', 'default_model', - 'default_res_id', 'default_content_subtype', 'default_subject', - 'default_body', 'active_id', 'lang', 'bin_raw', 'tz', - 'active_model', 'edi_web_url_view', 'active_ids', - 'default_attachment_ids'] - for (var key in action.context) { - if (_.indexOf(context_keys, key) == -1) { - action.context[key] = null; - } - } - /* end hack */ - } - return this._super.apply(this, arguments); - }, - }); - - /** * ------------------------------------------------------------ * ChatterUtils