[FIX] [IMP] mail: fixed mail sent to users being redirected to their partner profile

leading to potential issues.

Now the behavior is back to its previous version, posting on the user creates a private
discussion. Fixed management of model variable in message_post to avoid posting messages
on the mail.thread model.

Classic inbox writes on partner, with hr it writes on the employee profile, like previously.
This commit is contained in:
Thibault Delavallée 2014-08-28 12:41:44 +02:00
parent 4a731b2b22
commit 9094d768d0
4 changed files with 17 additions and 8 deletions

View File

@ -1549,8 +1549,8 @@ class mail_thread(osv.AbstractModel):
# set in the context.
model = False
if thread_id:
model = context.get('thread_model', self._name) if self._name == 'mail.thread' else self._name
if model != self._name and hasattr(self.pool[model], 'message_post'):
model = context.get('thread_model', False) if self._name == 'mail.thread' else self._name
if model and model != self._name and hasattr(self.pool[model], 'message_post'):
del context['thread_model']
return self.pool[model].message_post(cr, uid, thread_id, body=body, subject=subject, type=type, subtype=subtype, parent_id=parent_id, attachments=attachments, context=context, content_subtype=content_subtype, **kwargs)
@ -1603,7 +1603,7 @@ class mail_thread(osv.AbstractModel):
self.message_subscribe(cr, uid, [thread_id], list(partner_to_subscribe), context=context)
# _mail_flat_thread: automatically set free messages to the first posted message
if self._mail_flat_thread and not parent_id and thread_id:
if self._mail_flat_thread and model and not parent_id and thread_id:
message_ids = mail_message.search(cr, uid, ['&', ('res_id', '=', thread_id), ('model', '=', model)], context=context, order="id ASC", limit=1)
parent_id = message_ids and message_ids[0] or False
# we want to set a parent: force to set the parent_id to the oldest ancestor, to avoid having more than 1 level of thread
@ -1622,7 +1622,7 @@ class mail_thread(osv.AbstractModel):
values.update({
'author_id': author_id,
'model': model,
'res_id': thread_id or False,
'res_id': model and thread_id or False,
'body': body,
'subject': subject or False,
'type': type,
@ -1644,7 +1644,7 @@ class mail_thread(osv.AbstractModel):
# done with SUPERUSER_ID, because on some models users can post only with read access, not necessarily write access
self.write(cr, SUPERUSER_ID, [thread_id], {'message_last_post': fields.datetime.now()}, context=context)
message = mail_message.browse(cr, uid, msg_id, context=context)
if message.author_id and thread_id and type != 'notification' and not context.get('mail_create_nosubscribe'):
if message.author_id and model and thread_id and type != 'notification' and not context.get('mail_create_nosubscribe'):
self.message_subscribe(cr, uid, [thread_id], [message.author_id.id], context=context)
return msg_id

View File

@ -8,6 +8,7 @@
<field name="context">{
'default_model': 'res.users',
'default_res_id': uid,
'thread_model': 'res.partner',
'needaction_menu_ref': ['mail.mail_tomefeeds', 'mail.mail_starfeeds']
}</field>
<field name="params" eval="&quot;{
@ -38,6 +39,7 @@
<field name="context">{
'default_model': 'res.users',
'default_res_id': uid,
'thread_model': 'res.partner',
'search_default_message_unread': True,
'needaction_menu_ref': ['mail.mail_starfeeds', 'mail.mail_inboxfeeds']
}</field>
@ -65,6 +67,7 @@
<field name="context">{
'default_model': 'res.users',
'default_res_id': uid,
'thread_model': 'res.partner',
'search_default_message_unread': True
}</field>
<field name="params" eval="&quot;{
@ -92,6 +95,7 @@
<field name="context">{
'default_model': 'res.users',
'default_res_id': uid,
'thread_model': 'res.partner',
'needaction_menu_ref': ['mail.mail_tomefeeds', 'mail.mail_starfeeds', 'mail.mail_inboxfeeds']
}</field>
<field name="params" eval="&quot;{

View File

@ -118,7 +118,7 @@ class res_users(osv.Model):
@api.cr_uid_ids_context
def message_post(self, cr, uid, thread_id, context=None, **kwargs):
""" Redirect the posting of message on res.users to the related partner.
""" Redirect the posting of message on res.users as a private discussion.
This is done because when giving the context of Chatter on the
various mailboxes, we do not have access to the current partner_id. """
if isinstance(thread_id, (list, tuple)):
@ -136,7 +136,9 @@ class res_users(osv.Model):
if user_pid not in current_pids:
partner_ids.append(user_pid)
kwargs['partner_ids'] = partner_ids
return self.pool['res.partner'].message_post(cr, uid, user_pid, **kwargs)
if context and context.get('thread_model') == 'res.partner':
return self.pool['res.partner'].message_post(cr, uid, user_pid, **kwargs)
return self.pool['mail.thread'].message_post(cr, uid, uid, **kwargs)
def message_update(self, cr, uid, ids, msg_dict, update_vals=None, context=None):
return True

View File

@ -17,6 +17,7 @@
<field name="context">{
'default_model': 'res.users',
'default_res_id': uid,
'thread_model': 'res.partner',
}</field>
<field name="params" eval="&quot;{
'domain': [
@ -47,6 +48,7 @@
<field name="context">{
'default_model': 'res.users',
'default_res_id': uid,
'thread_model': 'res.partner',
'search_default_message_unread': True
}</field>
<field name="params" eval="&quot;{
@ -76,7 +78,8 @@
<field name="tag">mail.wall</field>
<field name="context">{
'default_model': 'res.users',
'default_res_id': uid
'default_res_id': uid,
'thread_model': 'res.partner',
}</field>
<field name="params" eval="&quot;{
'domain': [