Skip to content
Permalink
Browse files

[REF] mail, various : make message_get_default_recipients from mail t…

…hread private

Purpose: make some methods from mail.thread mixin private and update their
naming if necessary. Less publicly available mixin methods from mail.thread
means less requirements on information leak checks.

In this commit we put message_get_default_recipients as private as it is
not intended to be used externally. Its signature is improved to clearly
separate model-inherited method (overriden in some addons) and general tool
method given by the mixin.

Some addons are updated accordingly to the method change.

Related to task ID 1911679
PR odoo#29483
  • Loading branch information...
dbeguin authored and tde-banana-odoo committed Dec 12, 2018
1 parent b27e60b commit 25070443773c25997dd964e4f32ed3e7f2a3969e
@@ -1163,13 +1163,12 @@ def get_formview_id(self, access_uid=None):
return view_id

@api.multi
def message_get_default_recipients(self):
return {
r.id : {'partner_ids': [],
'email_to': r.email_normalized,
'email_cc': False}
for r in self.sudo()
}
def _message_get_default_recipients(self):
return {r.id: {
'partner_ids': [],
'email_to': r.email_normalized,
'email_cc': False}
for r in self}

@api.multi
def message_get_suggested_recipients(self):
@@ -492,15 +492,14 @@ def message_get_suggested_recipients(self):
return recipients

@api.multi
def message_get_default_recipients(self):
def _message_get_default_recipients(self):
# Prioritize registration email over partner_id, which may be shared when a single
# partner booked multiple seats
return {
r.id: {'partner_ids': [],
'email_to': r.email,
'email_cc': False}
for r in self
}
return {r.id: {
'partner_ids': [],
'email_to': r.email,
'email_cc': False}
for r in self}

def _message_post_after_hook(self, message, *args, **kwargs):
if self.email and not self.partner_id:
@@ -379,7 +379,8 @@ def generate_recipients(self, results, res_ids):
self.ensure_one()

if self.use_default_to or self._context.get('tpl_force_default_to'):
default_recipients = self.env['mail.thread'].message_get_default_recipients(res_model=self.model, res_ids=res_ids)
records = self.env[self.model].browse(res_ids).sudo()
default_recipients = self.env['mail.thread']._message_get_default_recipients_on_records(records)
for res_id, recipients in default_recipients.items():
results[res_id].pop('partner_to', None)
results[res_id].update(recipients)
@@ -1688,28 +1688,28 @@ def message_parse(self, message, save_original=False):
# Recipient management
# ------------------------------------------------------

@api.multi
def message_get_default_recipients(self, res_model=None, res_ids=None):
if res_model and res_ids:
if hasattr(self.env[res_model], 'message_get_default_recipients'):
return self.env[res_model].browse(res_ids).message_get_default_recipients()
records = self.env[res_model].sudo().browse(res_ids)
else:
records = self.sudo()
@api.model
def _message_get_default_recipients_on_records(self, records):
""" Generic implementation for finding default recipient to mail on
a recordset. ``_message_get_default_recipients`` may be defined to
implement custom behavior. """
if hasattr(records, '_message_get_default_recipients'):
return records._message_get_default_recipients()

res = {}
for record in records:
recipient_ids, email_to, email_cc = set(), False, False
if 'partner_id' in self._fields and record.partner_id:
recipient_ids.add(record.partner_id.id)
elif 'email_normalized' in self._fields and record.email_normalized:
recipient_ids, email_to, email_cc = [], False, False
if 'partner_id' in self and record.partner_id:
recipient_ids.append(record.partner_id.id)
elif 'email_normalized' in self and record.email_normalized:
email_to = record.email_normalized
elif 'email_from' in self._fields and record.email_from:
elif 'email_from' in self and record.email_from:
email_to = record.email_from
elif 'partner_email' in self._fields and record.partner_email:
elif 'partner_email' in self and record.partner_email:
email_to = record.partner_email
elif 'email' in self._fields:
elif 'email' in self and record.email:
email_to = record.email
res[record.id] = {'partner_ids': list(recipient_ids), 'email_to': email_to, 'email_cc': email_cc}
res[record.id] = {'partner_ids': recipient_ids, 'email_to': email_to, 'email_cc': email_cc}
return res

@api.multi
@@ -34,8 +34,12 @@ def message_get_suggested_recipients(self):
return recipients

@api.multi
def message_get_default_recipients(self):
return dict((res_id, {'partner_ids': [res_id], 'email_to': False, 'email_cc': False}) for res_id in self.ids)
def _message_get_default_recipients(self):
return {r.id: {
'partner_ids': [r.id],
'email_to': False,
'email_cc': False}
for r in self}

@api.model
def _notify_prepare_template_context(self, message, record, model_description=False, mail_auto_delete=True):
@@ -467,7 +467,7 @@ def render_message(self, res_ids):
template rendering represent a significant part of the process.
Default recipients are also computed, based on mail_thread method
message_get_default_recipients. This allows to ensure a mass mailing has
_message_get_default_recipients. This allows to ensure a mass mailing has
always some recipients specified.
:param browse wizard: current mail.compose.message browse record
@@ -488,7 +488,8 @@ def render_message(self, res_ids):
replies_to = self.env['mail.template']._render_template(self.reply_to, self.model, res_ids)
default_recipients = {}
if not self.partner_ids:
default_recipients = self.env['mail.thread'].message_get_default_recipients(res_model=self.model, res_ids=res_ids)
records = self.env[self.model].browse(res_ids).sudo()
default_recipients = self.env['mail.thread']._message_get_default_recipients_on_records(records)

results = dict.fromkeys(res_ids, False)
for res_id in res_ids:
@@ -287,8 +287,12 @@ def add_to_list(self, name, list_id):
return contact.name_get()[0]

@api.multi
def message_get_default_recipients(self):
return dict((record.id, {'partner_ids': [], 'email_to': record.email_normalized, 'email_cc': False}) for record in self)
def _message_get_default_recipients(self):
return {r.id: {
'partner_ids': [],
'email_to': r.email_normalized,
'email_cc': False}
for r in self}


class MassMailingStage(models.Model):

0 comments on commit 2507044

Please sign in to comment.
You can’t perform that action at this time.