[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:
@@ -30,13 +30,3 @@ class MailThread(models.AbstractModel):
|
||||
self.env['rating.rating'].browse(rating_id).write({'message_id': message.id})
|
||||
|
||||
return message
|
||||
|
||||
def _message_create(self, values_list):
|
||||
""" Force usage of rating-specific methods and API allowing to delegate
|
||||
computation to records. Keep methods optimized and skip rating_ids
|
||||
support to simplify MailThrad main API. """
|
||||
if not isinstance(values_list, (list)):
|
||||
values_list = [values_list]
|
||||
if any(values.get('rating_ids') for values in values_list):
|
||||
raise ValueError(_("Posting a rating should be done using message post API."))
|
||||
return super()._message_create(values_list)
|
||||
|
||||
Reference in New Issue
Block a user