From 5dfcdb74e5fb3665d42e9e7d2456fa6d2848db7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 14 Jan 2022 10:32:52 +0000 Subject: [PATCH] [FIX] mail: prevent inconsistencies when using message reply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes odoo/odoo#86060 X-original-commit: 81ddfad51e9b35db8d14e1fb14aa24596b6af767 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/models/mail_channel.py | 3 ++- addons/mail/tests/test_mail_channel.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 88359753dd7..0d388134eb6 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -579,7 +579,8 @@ class Channel(models.Model): def _message_compute_parent_id(self, parent_id): # super() unravels the chain of parents to set parent_id as the first # ancestor. We don't want that in channel. - return parent_id + parent_message = self.env['mail.message'].search([('id', '=', parent_id), ('model', '=', 'mail.channel'), ('res_id', '=', self.id)]) + return parent_message.id @api.returns('mail.message', lambda value: value.id) def message_post(self, *, message_type='notification', **kwargs): diff --git a/addons/mail/tests/test_mail_channel.py b/addons/mail/tests/test_mail_channel.py index d45fd66ea90..fa25834a28a 100644 --- a/addons/mail/tests/test_mail_channel.py +++ b/addons/mail/tests/test_mail_channel.py @@ -354,6 +354,14 @@ class TestChannelInternals(MailCommon): "Last message id should stay the same after mark channel as seen with an older message" ) + def test_channel_message_post_should_not_allow_adding_wrong_parent(self): + channels = self.env['mail.channel'].create([{'name': '1'}, {'name': '2'}]) + message = self._add_messages(channels[0], 'Body1') + message_format2 = channels[1].message_post(body='Body2', parent_id=message.id) + self.assertFalse(message_format2['parent_id'], "should not allow parent from wrong thread") + message_format3 = channels[1].message_post(body='Body3', parent_id=message.id + 100) + self.assertFalse(message_format3['parent_id'], "should not allow non-existing parent") + @mute_logger('odoo.models.unlink') def test_channel_unsubscribe_auto(self): """ Archiving / deleting a user should automatically unsubscribe related