From 685c76aad22392f01d0561eb8bc067494b8af30c Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Fri, 19 Nov 2021 11:53:35 +0000 Subject: [PATCH] [FIX] mail_group: only check members based on email and no author_id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In v15, in _find_members, we try to find a members with an email and without partner_id or a member with the partner_id provided (if provided). This commit remove the author_id, and so the partner_id to only looking for members based on their email address. Author_id could be the wrong since email is not uniq on partner. We retrieve the same behavior than previously from this way. courtesy of std for help to find a solution closes odoo/odoo#80638 X-original-commit: 98d7b1417ee82fefcef175dd83ab41cd89db5119 Signed-off-by: Jérémy Kersten (jke) --- addons/mail_group/models/mail_group.py | 4 +--- addons/mail_group/tests/test_mail_group.py | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/addons/mail_group/models/mail_group.py b/addons/mail_group/models/mail_group.py index 8794ef8029a..525ddcce0e2 100644 --- a/addons/mail_group/models/mail_group.py +++ b/addons/mail_group/models/mail_group.py @@ -251,9 +251,7 @@ class MailGroup(models.Model): if alias.alias_contact == 'followers': # Members only - author_id = message_dict.get('author_id', None) - email_from = message_dict.get('email_from') - if not self._find_member(email_from, author_id): + if not self._find_member(message_dict.get('email_from')): return _('Only members can send email to the mailing list.') # Skip the verification because the partner is in the member list return diff --git a/addons/mail_group/tests/test_mail_group.py b/addons/mail_group/tests/test_mail_group.py index f8d8b89c95a..065ec7cdbb0 100644 --- a/addons/mail_group/tests/test_mail_group.py +++ b/addons/mail_group/tests/test_mail_group.py @@ -78,6 +78,30 @@ class TestMailGroup(TestMailListCommon): member = self.test_group._find_member(email, partner_2.id) self.assertFalse(member, 'Should not return any member because the only one with the same email has a different partner') + def test_find_member_for_alias(self): + """Test the matching of a mail_group.members, when 2 users have the same partner email, and + that the first user was subscribed.""" + user = self.user_portal + user2 = mail_new_test_user(self.env, login='login_2', email=user.email) + + member = self.env['mail.group.member'].create({ + # subscribe with the first user + 'partner_id': user.partner_id.id, + 'mail_group_id': self.test_group.id, + }) + self.assertEqual(member.email, user.email) + + # In case of matching, function return a falsy value. + # Should not return string (exception) if at least one members have the same email, whatever + # the partner (author_id) that could match this email. + msg_dict = { + # send mail with the second user + 'author_id': user2.partner_id.id, + 'email_from': user2.email, + } + self.test_group.alias_id.alias_contact = 'followers' + self.assertFalse(self.test_group._alias_get_error_message({}, msg_dict, self.test_group.alias_id)) + @users('employee') def test_join_group(self): mail_group = self.env['mail.group'].browse(self.test_group.ids)