[FIX] mail: fixed recipients of private discussion, that were not correct. Author could be notified of their own reply independently of the specified recipients. Added tests for private discussions.
bzr revid: tde@openerp.com-20130403121307-4rixx7ct6y86spoz
This commit is contained in:
@@ -967,12 +967,15 @@ class mail_thread(osv.AbstractModel):
|
||||
], limit=1, context=context)
|
||||
if author_ids:
|
||||
kwargs['author_id'] = author_ids[0]
|
||||
author_id = kwargs.get('author_id')
|
||||
if author_id is None: # keep False values
|
||||
author_id = self.pool.get('mail.message')._get_default_author(cr, uid, context=context)
|
||||
|
||||
# 1: Handle content subtype: if plaintext, converto into HTML
|
||||
if content_subtype == 'plaintext':
|
||||
body = tools.plaintext2html(body)
|
||||
|
||||
# 2: Private message: add recipients (recipients and author of parent message)
|
||||
# 2: Private message: add recipients (recipients and author of parent message) - current author
|
||||
# + legacy-code management (! we manage only 4 and 6 commands)
|
||||
partner_ids = set()
|
||||
kwargs_partner_ids = kwargs.pop('partner_ids', [])
|
||||
@@ -985,12 +988,13 @@ class mail_thread(osv.AbstractModel):
|
||||
partner_ids.add(partner_id)
|
||||
else:
|
||||
pass # we do not manage anything else
|
||||
|
||||
if parent_id and not model:
|
||||
parent_message = mail_message.browse(cr, uid, parent_id, context=context)
|
||||
partner_ids |= set([partner.id for partner in parent_message.partner_ids])
|
||||
private_followers = set([partner.id for partner in parent_message.partner_ids])
|
||||
if parent_message.author_id:
|
||||
partner_ids.add(parent_message.author_id.id)
|
||||
private_followers.add(parent_message.author_id.id)
|
||||
private_followers -= set([author_id])
|
||||
partner_ids |= private_followers
|
||||
|
||||
# 3. Attachments
|
||||
# - HACK TDE FIXME: Chatter: attachments linked to the document (not done JS-side), load the message
|
||||
@@ -1051,6 +1055,7 @@ class mail_thread(osv.AbstractModel):
|
||||
|
||||
values = kwargs
|
||||
values.update({
|
||||
'author_id': author_id,
|
||||
'model': model,
|
||||
'res_id': thread_id or False,
|
||||
'body': body,
|
||||
|
||||
@@ -372,4 +372,55 @@ class TestMailgateway(TestMailBase):
|
||||
|
||||
def test_20_private_discussion(self):
|
||||
""" Testing private discussion between partners. """
|
||||
pass
|
||||
cr, uid = self.cr, self.uid
|
||||
|
||||
# Do: Raoul writes to Bert and Administrator, with a thread_model in context that should not be taken into account
|
||||
msg1_pids = [self.partner_admin_id, self.partner_bert_id]
|
||||
msg1_id = self.mail_thread.message_post(cr, self.user_raoul_id, False,
|
||||
partner_ids=msg1_pids,
|
||||
subtype='mail.mt_comment',
|
||||
context={'thread_model': 'mail.group'})
|
||||
|
||||
# Test: message recipients
|
||||
msg = self.mail_message.browse(cr, uid, msg1_id)
|
||||
msg_pids = [p.id for p in msg.partner_ids]
|
||||
msg_nids = [p.id for p in msg.notified_partner_ids]
|
||||
test_pids = msg1_pids
|
||||
test_nids = msg1_pids
|
||||
self.assertEqual(set(msg_pids), set(test_pids),
|
||||
'message_post: private discussion: incorrect recipients')
|
||||
self.assertEqual(set(msg_nids), set(test_nids),
|
||||
'message_post: private discussion: incorrect notified recipients')
|
||||
self.assertEqual(msg.model, False,
|
||||
'message_post: private discussion: context key "thread_model" not correctly ignored when having no res_id')
|
||||
|
||||
# Do: Bert replies through mailgateway (is a customer)
|
||||
msg2_id = self.mail_thread.message_post(cr, uid, False,
|
||||
author_id=self.partner_bert_id,
|
||||
parent_id=msg1_id, subtype='mail.mt_comment')
|
||||
|
||||
# Test: message recipients
|
||||
msg = self.mail_message.browse(cr, uid, msg2_id)
|
||||
msg_pids = [p.id for p in msg.partner_ids]
|
||||
msg_nids = [p.id for p in msg.notified_partner_ids]
|
||||
test_pids = [self.partner_admin_id, self.partner_raoul_id]
|
||||
test_nids = test_pids
|
||||
self.assertEqual(set(msg_pids), set(test_pids),
|
||||
'message_post: private discussion: incorrect recipients when replying')
|
||||
self.assertEqual(set(msg_nids), set(test_nids),
|
||||
'message_post: private discussion: incorrect notified recipients when replying')
|
||||
|
||||
# Do: Administrator replies
|
||||
msg3_id = self.mail_thread.message_post(cr, uid, False,
|
||||
parent_id=msg2_id, subtype='mail.mt_comment')
|
||||
|
||||
# Test: message recipients
|
||||
msg = self.mail_message.browse(cr, uid, msg3_id)
|
||||
msg_pids = [p.id for p in msg.partner_ids]
|
||||
msg_nids = [p.id for p in msg.notified_partner_ids]
|
||||
test_pids = [self.partner_bert_id, self.partner_raoul_id]
|
||||
test_nids = test_pids
|
||||
self.assertEqual(set(msg_pids), set(test_pids),
|
||||
'message_post: private discussion: incorrect recipients when replying')
|
||||
self.assertEqual(set(msg_nids), set(test_nids),
|
||||
'message_post: private discussion: incorrect notified recipients when replying')
|
||||
|
||||
Reference in New Issue
Block a user