From 1a2a8d82feb695b9fdef61707a86808d4a3b8eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2023 11:41:31 +0000 Subject: [PATCH] [FIX] mail: do not subscribe inactive users creating records Inactive users should not be added in followers of records, especially using automated subscription. Indeed they mainly generate noise in notification process and are generally skipped. Few use case exists of inactive users creating records. One use case is the mailgateway running as root but a context key 'mail_create_nosubscribe' is used to avoid it. Other use cases include automated action for example who are also generally protected. Anyway better be sure and consider this is a standard use case. To extend this rationale, inactive people are currently not added when posting. It therefore makes sense to keep this behavior coherent through the mail stack. Task-3046371 (Mail: Better Language Support in Composer) Part-of: odoo/odoo#113522 --- addons/mail/models/mail_thread.py | 2 +- addons/test_mail/tests/test_mail_followers.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 18960992d0e..f9d3da88868 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -257,7 +257,7 @@ class MailThread(models.AbstractModel): threads = super(MailThread, self).create(vals_list) # subscribe uid unless asked not to - if not self._context.get('mail_create_nosubscribe') and threads: + if not self._context.get('mail_create_nosubscribe') and threads and self.env.user.active: self.env['mail.followers']._insert_followers( threads._name, threads.ids, self.env.user.partner_id.ids, subtypes=None, diff --git a/addons/test_mail/tests/test_mail_followers.py b/addons/test_mail/tests/test_mail_followers.py index 5670869f928..dfedff9d386 100644 --- a/addons/test_mail/tests/test_mail_followers.py +++ b/addons/test_mail/tests/test_mail_followers.py @@ -325,8 +325,8 @@ class AdvancedFollowersTest(TestMailCommon): }) self.assertFalse(new_record.message_partner_ids, 'Filters out inactive partners') - self.assertEqual(new_record.message_follower_ids.partner_id, self.partner_admin, - 'TODO: should not subscribe inactive partner') + self.assertFalse(new_record.message_follower_ids.partner_id, + 'Does not subscribe inactive partner') def test_auto_subscribe_post(self): """ People posting a message are automatically added as followers """