From 930c6fd46c70cd2b21dbd6ddf1a7d50f9afe9ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 20 Jan 2021 10:50:22 +0000 Subject: [PATCH] [IMP] mail, test_mail: allow to bypass user / channel group-based subscription A context key is added allowing to bypass user / channel synchronization when creating users. This is used notably in tests to avoid subscribing new test users to "general" channel created as default data. Purpose is to avoid interferences in query-based performance tests. It also avoids unnecessary data creation and/or update when it is not necessary especially in tests. LINKS Task ID-2070632 (main task) Task ID-2419762 (followup task) COM PR odoo/odoo#62859 ENT PR odoo/enterprise#15172 UPG PR odoo/upgrade#2005 --- addons/mail/models/res_users.py | 5 +++-- addons/test_mail/tests/test_performance.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/res_users.py b/addons/mail/models/res_users.py index f663a1c9f5e..4455cc70f63 100644 --- a/addons/mail/models/res_users.py +++ b/addons/mail/models/res_users.py @@ -80,8 +80,9 @@ GROUP BY channel_moderator.res_users_id""", [tuple(self.ids)]) raise exceptions.RedirectWarning(msg, action.id, _('Go to the configuration panel')) users = super(Users, self).create(vals_list) - # Auto-subscribe to channels - self.env['mail.channel'].search([('group_ids', 'in', users.groups_id.ids)])._subscribe_users() + # Auto-subscribe to channels unless skip explicitly requested + if not self.env.context.get('mail_channel_nosubscribe'): + self.env['mail.channel'].search([('group_ids', 'in', users.groups_id.ids)])._subscribe_users() return users def write(self, vals): diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index 37095b8e79c..6651549d9c0 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -18,6 +18,7 @@ class BaseMailPerformance(TransactionCaseWithUserDemo): 'mail_create_nolog': True, 'mail_create_nosubscribe': True, 'mail_notrack': True, + 'mail_channel_nosubscribe': True, } self.user_employee = self.env['res.users'].with_context(self._quick_create_ctx).create({ 'name': 'Ernest Employee',