[FIX] mail, test_mail: don't notify inactive users
We don't want to notify inactive followers, especially in the case of oddobot that was considered as a inactive partner in _notify_compute_recipients. The computed recipient data for odoobot are (pid:2 active:False pshare:True notif:None) It was considered as a partner and notified by email. This fix simply removes inactive partner from partner to notify. closes odoo/odoo#31734 Signed-off-by: Toufik Benjaa (tbe) <tbe@odoo.com>
This commit is contained in:
@@ -1079,6 +1079,9 @@ class Message(models.Model):
|
||||
if pid and pid == author_id and not self.env.context.get('mail_notify_author'): # do not notify the author of its own messages
|
||||
continue
|
||||
if pid:
|
||||
if active is False:
|
||||
# avoid to notify inactive partner by email (odoobot)
|
||||
continue
|
||||
pdata = {'id': pid, 'active': active, 'share': pshare, 'groups': groups}
|
||||
if notif == 'inbox':
|
||||
recipient_data['partners'].append(dict(pdata, notif=notif, type='user'))
|
||||
|
||||
@@ -96,6 +96,20 @@ class TestNotifications(BaseFunctionalTest, MockEmails):
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment',
|
||||
partner_ids=[self.user_employee.partner_id.id])
|
||||
|
||||
def test_inactive_follower(self):
|
||||
# In some case odoobot is follower of a record.
|
||||
# Even if it shouldn't be the case, we want to be sure that odoobot is not notified
|
||||
self.test_record._message_subscribe(self.user_employee.partner_id.ids)
|
||||
with self.assertNotifications(partner_employee=(1, 'inbox', 'unread')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment')
|
||||
self.user_employee.active = False
|
||||
# at this point, partner is still active and would receive an email notification
|
||||
self.user_employee.partner_id._write({'active': False})
|
||||
with self.assertNotifications(partner_employee=(0, '', '')):
|
||||
self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment')
|
||||
|
||||
def test_set_message_done_user(self):
|
||||
with self.assertNotifications(partner_employee=(0, '', '')):
|
||||
message = self.test_record.message_post(
|
||||
|
||||
@@ -486,14 +486,18 @@ class TestMailgateway(BaseFunctionalTest, MockEmails):
|
||||
@mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_private_discussion(self):
|
||||
""" Testing private discussion between partners. """
|
||||
msg1_pids = [self.env.user.partner_id.id, self.partner_1.id]
|
||||
self.partner_2 = self.env['res.partner'].with_context(BaseFunctionalTest._test_context).create({
|
||||
'name': 'Admin',
|
||||
'email': 'admin@agrolait.com',
|
||||
})
|
||||
msg1_pids = [self.partner_1.id, self.partner_2.id]
|
||||
|
||||
# Do: Raoul writes to Bert and Administrator, with a model specific by parameter that should not be taken into account
|
||||
msg1 = self.env['mail.thread'].sudo(self.user_employee).message_post(partner_ids=msg1_pids, subtype='mail.mt_comment', model='mail.test')
|
||||
|
||||
# Test: message recipients
|
||||
msg = self.env['mail.message'].browse(msg1.id)
|
||||
self.assertEqual(msg.partner_ids, self.env.user.partner_id | self.partner_1,
|
||||
self.assertEqual(msg.partner_ids, self.partner_2 | self.partner_1,
|
||||
'message_post: private discussion: incorrect recipients')
|
||||
self.assertEqual(msg.model, False,
|
||||
'message_post: private discussion: parameter model not correctly ignored when having no res_id')
|
||||
@@ -510,7 +514,7 @@ class TestMailgateway(BaseFunctionalTest, MockEmails):
|
||||
# Test: message recipients
|
||||
self.assertEqual(msg2.author_id, self.partner_1,
|
||||
'message_post: private discussion: wrong author through mailgateway based on email')
|
||||
self.assertEqual(msg2.partner_ids, self.user_employee.partner_id | self.env.user.partner_id,
|
||||
self.assertEqual(msg2.partner_ids, self.user_employee.partner_id | self.partner_2,
|
||||
'message_post: private discussion: incorrect recipients when replying')
|
||||
|
||||
# Do: Bert replies through chatter (is a customer)
|
||||
@@ -518,9 +522,9 @@ class TestMailgateway(BaseFunctionalTest, MockEmails):
|
||||
|
||||
# Test: message recipients
|
||||
msg = self.env['mail.message'].browse(msg3.id)
|
||||
self.assertEqual(msg.partner_ids, self.user_employee.partner_id | self.env.user.partner_id,
|
||||
self.assertEqual(msg.partner_ids, self.user_employee.partner_id | self.partner_2,
|
||||
'message_post: private discussion: incorrect recipients when replying')
|
||||
self.assertEqual(msg.needaction_partner_ids, self.user_employee.partner_id | self.env.user.partner_id,
|
||||
self.assertEqual(msg.needaction_partner_ids, self.user_employee.partner_id | self.partner_2,
|
||||
'message_post: private discussion: incorrect notified recipients when replying')
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models', 'odoo.addons.mail.models.mail_mail')
|
||||
|
||||
@@ -70,9 +70,20 @@ tour.register('shop_mail', {
|
||||
trigger: '.btn[name="action_quotation_send"]',
|
||||
extra_trigger: '.o_statusbar_status .btn-primary:contains("Sales Order")',
|
||||
},
|
||||
{
|
||||
content: "Open recipients dropdown",
|
||||
trigger: '.o_field_many2one[name="partner_ids"] .ui-autocomplete-input',
|
||||
run: 'click',
|
||||
},
|
||||
{
|
||||
content: "Select azure interior",
|
||||
trigger: '.ui-menu-item a:contains(Interior24)',
|
||||
in_modal: false,
|
||||
},
|
||||
{
|
||||
content: "click Send email",
|
||||
trigger: '.btn[name="action_send_mail"]',
|
||||
extra_trigger: '.o_badge_text:contains("Azure")',
|
||||
},
|
||||
{
|
||||
content: "wait mail to be sent, and go see it",
|
||||
|
||||
Reference in New Issue
Block a user