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
'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. """
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']: