[FIX] mail: prevent inconsistencies when using message reply

closes odoo/odoo#86060

X-original-commit: 81ddfad51e9b35db8d14e1fb14aa24596b6af767
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Sébastien Theys
2022-03-09 00:50:49 +00:00
parent b81cddea92
commit 5dfcdb74e5
2 changed files with 10 additions and 1 deletions
+2 -1
View File
@@ -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):
+8
View File
@@ -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