[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
This commit is contained in:
Thibault Delavallée
2023-02-23 18:28:59 +01:00
parent 3fea6d05fa
commit 1a2a8d82fe
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -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,
@@ -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 """