[IMP] mail: add sanity checks for message_post and its helpers
Purpose of this commit is to clearly check input of ``message_post`` method and its main helpers in order to prevent wrong usage of message post API. Some values used to populate message fields should not be set directly when posting or logging messages. Indeed they may be part of other process (like notification process managed by ``_notify_thread``, or could be setup by custom routes like 'reaction_ids', or custom usage of 'model' and 'res_id' that could conflicts with record on which methods are called). We therefore add checks and cleanup in those methods to be sure the API is used as intended and avoid unwanted side effects. Task-2710804 (Mail: Clean MailThread Posting API) Part-of: odoo/odoo#99482
This commit is contained in:
@@ -361,7 +361,6 @@ class TestDiscuss(TestMailCommon, TestRecipients):
|
||||
channel = self.env['mail.channel'].create({'name': 'testChannel'})
|
||||
notification_msg = channel.with_user(self.user_admin).message_notify(
|
||||
body='test',
|
||||
message_type='user_notification',
|
||||
partner_ids=[self.partner_2.id],
|
||||
)
|
||||
|
||||
|
||||
@@ -403,6 +403,40 @@ class TestMessageNotify(TestMessagePostCommon):
|
||||
}
|
||||
)
|
||||
|
||||
@users('employee')
|
||||
def test_notify_parameters(self):
|
||||
""" Test usage of parameters in notify, both for unwanted side effects
|
||||
and magic parameters. """
|
||||
test_record = self.test_record.with_env(self.env)
|
||||
|
||||
for parameters in [
|
||||
{'message_type': 'comment'},
|
||||
{'canned_response_ids': []},
|
||||
{'child_ids': []},
|
||||
{'mail_ids': []},
|
||||
{'notification_ids': []},
|
||||
{'notified_partner_ids': []},
|
||||
{'reaction_ids': []},
|
||||
{'starred_partner_ids': []},
|
||||
]:
|
||||
with self.subTest(parameters=parameters), \
|
||||
self.mock_mail_gateway(), \
|
||||
self.assertRaises(ValueError):
|
||||
_new_message = test_record.message_notify(
|
||||
body='<p>You will not receive a notification</p>',
|
||||
partner_ids=self.partner_1.ids,
|
||||
subject='This should not be accepted',
|
||||
**parameters
|
||||
)
|
||||
|
||||
# support of subtype xml id
|
||||
new_message = test_record.message_notify(
|
||||
body='<p>You will not receive a notification</p>',
|
||||
partner_ids=self.partner_1.ids,
|
||||
subtype_xmlid='mail.mt_note',
|
||||
)
|
||||
self.assertEqual(new_message.subtype_id, self.env.ref('mail.mt_note'))
|
||||
|
||||
@users('employee')
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_notify_thread(self):
|
||||
|
||||
Reference in New Issue
Block a user