summaryrefslogtreecommitdiff
path: root/addons/test_mail/tests
diff options
context:
space:
mode:
authorbit-odoo <bit@odoo.com>2021-03-12 17:14:29 +0000
committerSébastien Theys <seb@odoo.com>2021-03-12 17:14:29 +0000
commit52acbfa5c4c6ef6eedfbe876da8817c8c41cbb42 (patch)
tree907db88931aea9819e295c7a27b71bc3c191737c /addons/test_mail/tests
parentf0a1e7c35bd8cd17149d1d54bfe5b9eec12a0814 (diff)
[FIX] mail, test_mail: avoid removing chat users on archive/delete
Before this commit: When deleting/archiving any user, the user’s related chat changed name due to losing one of its members. After this commit: Chat name should remain the same after archiving/deleting the user. Reasoning: The unsubscribe was meant to target channels of type channel specifically. `test_channel_auto_unsubscribe_archived_or_deleted_users` has been reintroduced after having been removed by mistake in eda542c82f84d7b5589846691b9cb6b7f1021947 task-2442235 closes odoo/odoo#67694 X-original-commit: 7844ed0a5fcf4a2139c355b8e640ba50ec818527 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/test_mail/tests')
-rw-r--r--addons/test_mail/tests/test_mail_channel.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/addons/test_mail/tests/test_mail_channel.py b/addons/test_mail/tests/test_mail_channel.py
index d81fb161bf4..ac47d8857b5 100644
--- a/addons/test_mail/tests/test_mail_channel.py
+++ b/addons/test_mail/tests/test_mail_channel.py
@@ -256,6 +256,49 @@ class TestChannelFeatures(TestMailCommon):
"Last message id should stay the same after mark channel as seen with an older message"
)
+ @mute_logger('odoo.models.unlink')
+ def test_channel_auto_unsubscribe_archived_or_deleted_users(self):
+ """Archiving / deleting a user should automatically unsubscribe related partner from private channels"""
+ test_channel_private = self.env['mail.channel'].with_context(self._test_context).create({
+ 'name': 'Winden caves',
+ 'description': 'Channel to travel through time',
+ 'public': 'private',
+ })
+ test_channel_group = self.env['mail.channel'].with_context(self._test_context).create({
+ 'name': 'Sic Mundus',
+ 'public': 'groups',
+ 'group_public_id': self.env.ref('base.group_user').id})
+
+ test_user = self.env['res.users'].create({
+ "login": "adam",
+ "name": "Jonas",
+ })
+ test_partner = test_user.partner_id
+ test_chat = self.env['mail.channel'].with_context(self._test_context).create({
+ 'name': 'test',
+ 'channel_type': 'chat',
+ 'public': 'private',
+ 'channel_partner_ids': [(4, self.user_employee.partner_id.id), (4, test_partner.id)],
+ })
+
+ self._join_channel(self.test_channel, self.user_employee.partner_id | test_partner)
+ self._join_channel(test_channel_private, self.user_employee.partner_id | test_partner)
+ self._join_channel(test_channel_group, self.user_employee.partner_id | test_partner)
+
+ # Unsubscribe archived user from the private channels, but not from public channels and not from chat
+ self.user_employee.active = False
+ self.assertEqual(test_channel_private.channel_partner_ids, test_partner)
+ self.assertEqual(test_channel_group.channel_partner_ids, test_partner)
+ 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)
+
+ # Unsubscribe deleted user from the private channels, but not from public channels and not from chat
+ test_user.unlink()
+ self.assertEqual(test_channel_private.channel_partner_ids, self.env['res.partner'])
+ self.assertEqual(test_channel_group.channel_partner_ids, self.env['res.partner'])
+ 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_multi_company_chat(self):
company_A = self.env['res.company'].create({'name': 'Company A'})
company_B = self.env['res.company'].create({'name': 'Company B'})