From 964dae231125fa73a3366ec417878bef457a1a60 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 6 Jan 2014 11:00:10 +0100 Subject: [PATCH] [FIX] mail: subscribe user at creation as a default value instead of post processing. This allows to have a value for the _set_followers call and be able to have record rules based on followers (eg: note.note). Set the priority of message_follower_ids fields to -10 to be sure it will be executed before other function fields using these followers (eg: _set_stage_per_user from note.note does a browse which would trigger record rules to read the note) bzr revid: mat@openerp.com-20140106100010-jl4cuvgvpsw26v28 --- addons/mail/mail_thread.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index c87df08eed4..4228b8440b6 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -286,7 +286,7 @@ class mail_thread(osv.AbstractModel): 'message_is_follower': fields.function(_get_followers, type='boolean', fnct_search=_search_is_follower, string='Is a Follower', multi='_get_followers,'), 'message_follower_ids': fields.function(_get_followers, fnct_inv=_set_followers, - fnct_search=_search_followers, type='many2many', + fnct_search=_search_followers, type='many2many', priority=-10, obj='res.partner', string='Followers', multi='_get_followers'), 'message_ids': fields.one2many('mail.message', 'res_id', domain=lambda self: [('model', '=', self._name)], @@ -317,16 +317,19 @@ class mail_thread(osv.AbstractModel): if context is None: context = {} + # subscribe uid unless asked not to + if not context.get('mail_create_nosubscribe'): + pid = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid).partner_id.id + message_follower_ids = values.get('message_follower_ids') or [] # webclient can send None or False + message_follower_ids.append([4, pid]) + values['message_follower_ids'] = message_follower_ids + thread_id = super(mail_thread, self).create(cr, uid, values, context=context) # automatic logging unless asked not to (mainly for various testing purpose) if not context.get('mail_create_nolog'): self.message_post(cr, uid, thread_id, body=_('%s created') % (self._description), context=context) - # subscribe uid unless asked not to - if not context.get('mail_create_nosubscribe'): - self.message_subscribe_users(cr, uid, [thread_id], [uid], context=context) - # auto_subscribe: take values and defaults into account create_values = dict(values) for key, val in context.iteritems():