[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
This commit is contained in:
parent
6389c33cd6
commit
964dae2311
|
@ -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():
|
||||
|
|
Loading…
Reference in New Issue