summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/mail/models/mail_channel.py3
-rw-r--r--addons/test_mail/tests/test_mail_channel.py30
2 files changed, 33 insertions, 0 deletions
diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py
index ab5033c4642..9781823ad20 100644
--- a/addons/mail/models/mail_channel.py
+++ b/addons/mail/models/mail_channel.py
@@ -322,6 +322,9 @@ class Channel(models.Model):
return self._action_unfollow(self.env.user.partner_id)
def _action_unfollow(self, partner):
+ self.message_unsubscribe(partner.ids)
+ if partner not in self.with_context(active_test=False).channel_partner_ids:
+ return True
channel_info = self.channel_info('unsubscribe')[0] # must be computed before leaving the channel (access rights)
result = self.write({'channel_partner_ids': [(3, partner.id)]})
# side effect of unsubscribe that wasn't taken into account because
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'})