From 5d25e9d7805df4fc72fe5365e078090fd9b22d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 20 Mar 2013 14:50:13 +0100 Subject: [PATCH] [FIX] mail_compose_message: fixed mass_mail subscribing the author to all documents, not the case anymore; fixed access rule on mail_compose_message not taking into account the wizard creation in mass_mail_mode (model but no res_id -> could lead to crash). bzr revid: tde@openerp.com-20130320135013-mryxzwssd346t78y --- addons/mail/wizard/mail_compose_message.py | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 0591d7fd932..0c123f2fc74 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -23,6 +23,7 @@ import base64 import re from openerp import tools +from openerp import SUPERUSER_ID from openerp.osv import osv from openerp.osv import fields from openerp.tools.safe_eval import safe_eval as eval @@ -126,6 +127,31 @@ class mail_compose_message(osv.TransientModel): 'partner_ids': lambda self, cr, uid, ctx={}: [], } + def check_access_rule(self, cr, uid, ids, operation, context=None): + """ Access rules of mail.compose.message: + - create: if + - model, no res_id, I create a message in mass mail mode + - then: fall back on mail.message acces rules + """ + if uid == SUPERUSER_ID: + return + if isinstance(ids, (int, long)): + ids = [ids] + + # Author condition (CREATE (mass_mail)) + if operation == 'create': + # Read mail_compose_message.ids to have their values + message_values = {} + cr.execute('SELECT DISTINCT id, model, res_id FROM "%s" WHERE id = ANY (%%s) AND res_id = 0' % self._table, (ids,)) + for id, rmod, rid in cr.fetchall(): + message_values[id] = {'model': rmod, 'res_id': rid} + + author_ids = [mid for mid, message in message_values.iteritems() + if message.get('model') and not message.get('res_id')] + ids = list(set(ids) - set(author_ids)) + + return super(mail_compose_message, self).check_access_rule(cr, uid, ids, operation, context=context) + def _notify(self, cr, uid, newid, context=None): """ Override specific notify method of mail.message, because we do not want that feature in the wizard. """ @@ -218,8 +244,11 @@ class mail_compose_message(osv.TransientModel): post_values.update(email_dict) # post the message subtype = 'mail.mt_comment' - if is_log or mass_mail_mode: + if is_log: # log a note: subtype is False subtype = False + elif mass_mail_mode: # mass mail: is a log pushed to recipients, author not added + subtype = False + context['mail_create_nosubscribe'] = True msg_id = active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values) # mass_mailing: notify specific partners, because subtype was False, and no-one was notified if mass_mail_mode and post_values['partner_ids']: