[FIX] mail, mail_group: fix override of _message_compute_author
This commit mainly fixes an override of ``_message_compute_author``. It is done with an incorrect default parameter value for raise_exception defaulting to False instead of True). By the way we also fix parameter naming in order to ease understanding. Part of Task-2710804 (Mail: Clean Mail.Thread API) Part-of: odoo/odoo#94660
This commit is contained in:
@@ -596,8 +596,8 @@ class Channel(models.Model):
|
||||
self._action_unfollow(p)
|
||||
return super(Channel, self)._message_receive_bounce(email, partner)
|
||||
|
||||
def _message_compute_author(self, author_id=None, email_from=None, raise_exception=False):
|
||||
return super()._message_compute_author(author_id=author_id, email_from=email_from, raise_exception=False)
|
||||
def _message_compute_author(self, author_id=None, email_from=None, raise_on_email=True):
|
||||
return super()._message_compute_author(author_id=author_id, email_from=email_from, raise_on_email=False)
|
||||
|
||||
def _message_compute_parent_id(self, parent_id):
|
||||
# super() unravels the chain of parents to set parent_id as the first
|
||||
|
||||
@@ -75,7 +75,7 @@ class Message(models.Model):
|
||||
missing_author = 'author_id' in fields and 'author_id' not in res
|
||||
missing_email_from = 'email_from' in fields and 'email_from' not in res
|
||||
if missing_author or missing_email_from:
|
||||
author_id, email_from = self.env['mail.thread']._message_compute_author(res.get('author_id'), res.get('email_from'), raise_exception=False)
|
||||
author_id, email_from = self.env['mail.thread']._message_compute_author(res.get('author_id'), res.get('email_from'), raise_on_email=False)
|
||||
if missing_email_from:
|
||||
res['email_from'] = email_from
|
||||
if missing_author:
|
||||
@@ -565,7 +565,7 @@ class Message(models.Model):
|
||||
tracking_values_list = []
|
||||
for values in values_list:
|
||||
if 'email_from' not in values: # needed to compute reply_to
|
||||
author_id, email_from = self.env['mail.thread']._message_compute_author(values.get('author_id'), email_from=None, raise_exception=False)
|
||||
_author_id, email_from = self.env['mail.thread']._message_compute_author(values.get('author_id'), email_from=None, raise_on_email=False)
|
||||
values['email_from'] = email_from
|
||||
if not values.get('message_id'):
|
||||
values['message_id'] = self._get_message_id(values)
|
||||
|
||||
@@ -1923,7 +1923,7 @@ class MailThread(models.AbstractModel):
|
||||
author_id, email_from = False, False
|
||||
else:
|
||||
author_guest_id = False
|
||||
author_id, email_from = self._message_compute_author(author_id, email_from, raise_exception=True)
|
||||
author_id, email_from = self._message_compute_author(author_id, email_from, raise_on_email=True)
|
||||
|
||||
if subtype_xmlid:
|
||||
subtype_id = self.env['ir.model.data']._xmlid_to_res_id(subtype_xmlid)
|
||||
@@ -2061,7 +2061,7 @@ class MailThread(models.AbstractModel):
|
||||
msg_kwargs = dict((key, val) for key, val in kwargs.items() if key in self.env['mail.message']._fields)
|
||||
notif_kwargs = dict((key, val) for key, val in kwargs.items() if key not in msg_kwargs)
|
||||
|
||||
author_id, email_from = self._message_compute_author(author_id, email_from, raise_exception=True)
|
||||
author_id, email_from = self._message_compute_author(author_id, email_from, raise_on_email=True)
|
||||
|
||||
if not partner_ids:
|
||||
_logger.warning('Message notify called without recipient_ids, skipping')
|
||||
@@ -2112,7 +2112,7 @@ class MailThread(models.AbstractModel):
|
||||
the log process. This method should be called within methods where
|
||||
access rights are already granted to avoid privilege escalation. """
|
||||
self.ensure_one()
|
||||
author_id, email_from = self._message_compute_author(author_id, email_from, raise_exception=False)
|
||||
author_id, email_from = self._message_compute_author(author_id, email_from, raise_on_email=False)
|
||||
|
||||
msg_values = {
|
||||
'subject': subject,
|
||||
@@ -2139,7 +2139,7 @@ class MailThread(models.AbstractModel):
|
||||
|
||||
:param bodies: dict {record_id: body}
|
||||
"""
|
||||
author_id, email_from = self._message_compute_author(author_id, email_from, raise_exception=False)
|
||||
author_id, email_from = self._message_compute_author(author_id, email_from, raise_on_email=False)
|
||||
|
||||
base_message_values = {
|
||||
'subject': subject,
|
||||
@@ -2164,10 +2164,15 @@ class MailThread(models.AbstractModel):
|
||||
# MAIL.MESSAGE HELPERS
|
||||
# ------------------------------------------------------------
|
||||
|
||||
def _message_compute_author(self, author_id=None, email_from=None, raise_exception=True):
|
||||
def _message_compute_author(self, author_id=None, email_from=None, raise_on_email=True):
|
||||
""" Tool method computing author information for messages. Purpose is
|
||||
to ensure maximum coherence between author / current user / email_from
|
||||
when sending emails. """
|
||||
when sending emails.
|
||||
|
||||
:param raise_on_email: if email_from is not found, raise an UserError
|
||||
|
||||
:return tuple: res.partner ID (may be False or None), email_from
|
||||
"""
|
||||
if author_id is None:
|
||||
if email_from:
|
||||
author = self._mail_find_partner_from_emails([email_from])[0]
|
||||
@@ -2182,8 +2187,8 @@ class MailThread(models.AbstractModel):
|
||||
email_from = author.email_formatted
|
||||
|
||||
# superuser mode without author email -> probably public user; anyway we don't want to crash
|
||||
if not email_from and not self.env.su and raise_exception:
|
||||
raise exceptions.UserError(_("Unable to log message, please configure the sender's email address."))
|
||||
if not email_from and raise_on_email and not self.env.su:
|
||||
raise exceptions.UserError(_("Unable to send message, please configure the sender's email address."))
|
||||
|
||||
return author_id, email_from
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class MailComposer(models.TransientModel):
|
||||
missing_author = 'author_id' in fields and 'author_id' not in result
|
||||
missing_email_from = 'email_from' in fields and 'email_from' not in result
|
||||
if missing_author or missing_email_from:
|
||||
author_id, email_from = self.env['mail.thread']._message_compute_author(result.get('author_id'), result.get('email_from'), raise_exception=False)
|
||||
author_id, email_from = self.env['mail.thread']._message_compute_author(result.get('author_id'), result.get('email_from'), raise_on_email=False)
|
||||
if missing_email_from:
|
||||
result['email_from'] = email_from
|
||||
if missing_author:
|
||||
|
||||
@@ -287,7 +287,7 @@ class MailGroup(models.Model):
|
||||
# First create the <mail.message>
|
||||
Mailthread = self.env['mail.thread']
|
||||
values = dict((key, val) for key, val in kwargs.items() if key in self.env['mail.message']._fields)
|
||||
author_id, email_from = Mailthread._message_compute_author(author_id, email_from, raise_exception=True)
|
||||
author_id, email_from = Mailthread._message_compute_author(author_id, email_from, raise_on_email=True)
|
||||
|
||||
values.update({
|
||||
'author_id': author_id,
|
||||
|
||||
Reference in New Issue
Block a user