summaryrefslogtreecommitdiff
path: root/addons/test_mail
diff options
context:
space:
mode:
authorQiuyu (QHO) <qho@odoo.com>2021-03-19 14:57:01 +0000
committerQiuyu (QHO) <qho@odoo.com>2021-03-23 15:58:09 +0000
commit1b09aeabe3e75dfd221c3ba089bdf94848c2a507 (patch)
tree40f948e45d611a14e240d68487ced6815ce3d1e8 /addons/test_mail
parent81a8be7d115ffcfac0126c252811381a482bd6a9 (diff)
[FIX] mail: unfollow only if the partner is in the channel
Before the commit, `_action_unfollow()` can be called by `_message_receive_bounce()` and then multiple leave notifications can be sent even if the partner has been removed from the channel, when the partner is a follower of the channel and without a valid email address. Unfollow action should also remove the partner from the followers, and only be processed if the partner is still a member of the channel. Task id: 2456233 closes odoo/odoo#68154 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/test_mail')
-rw-r--r--addons/test_mail/tests/test_mail_channel.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/addons/test_mail/tests/test_mail_channel.py b/addons/test_mail/tests/test_mail_channel.py
index ac47d8857b5..3fec6b8594c 100644
--- a/addons/test_mail/tests/test_mail_channel.py
+++ b/addons/test_mail/tests/test_mail_channel.py
@@ -299,6 +299,36 @@ class TestChannelFeatures(TestMailCommon):
self.assertEqual(self.test_channel.channel_partner_ids, self.user_employee.partner_id | test_partner)
self.assertEqual(test_chat.channel_partner_ids, self.user_employee.partner_id | test_partner)
+ def test_channel_unfollow_should_also_unsubscribe_the_partner(self):
+ self.test_channel.message_subscribe(self.test_partner.ids)
+ self.test_channel._action_unfollow(self.test_partner)
+
+ self.assertFalse(self.test_channel.message_partner_ids)
+
+ def test_channel_unfollow_should_not_post_message_if_the_partner_has_been_removed(self):
+ '''
+ When a partner leaves a channel, the system will help post a message under
+ that partner's name in the channel to notify others if `email_sent` is set `False`.
+ The message should only be posted when the partner is still a member of the channel
+ before method `_action_unfollow()` is called.
+ If the partner has been removed earlier, no more messages will be posted
+ even if `_action_unfollow()` is called again.
+ '''
+ self.test_channel.write({'email_send': False})
+ self._join_channel(self.test_channel, self.test_partner)
+ self.test_channel.message_subscribe(self.partner_employee.ids)
+
+ # a message should be posted to notify others when a partner is about to leave
+ with self.assertSinglePostNotifications([{'partner': self.partner_employee, 'type': 'inbox'}], {
+ 'message_type': 'notification',
+ 'subtype': 'mail.mt_comment',
+ }):
+ self.test_channel._action_unfollow(self.test_partner)
+
+ # no more messages should be posted if the partner has been removed before.
+ with self.assertNoNotifications():
+ self.test_channel._action_unfollow(self.test_partner)
+
def test_multi_company_chat(self):
company_A = self.env['res.company'].create({'name': 'Company A'})
company_B = self.env['res.company'].create({'name': 'Company B'})