mirror of
https://gitlab.com/flectra-hq/flectra.git
synced 2026-11-02 20:30:20 -06:00
[PATCH] Upstream patch - 20042022
This commit is contained in:
1 parent
822a36c69b
commit
5e72a9cdc8
15 files changed
+457
-52
No files matched your search
@@ -1464,10 +1464,16 @@ class MailThread(models.AbstractModel):
|
||||
|
||||
parent_ids = False
|
||||
if msg_dict['in_reply_to']:
|
||||
parent_ids = self.env['mail.message'].search([('message_id', '=', msg_dict['in_reply_to'])], limit=1)
|
||||
parent_ids = self.env['mail.message'].search(
|
||||
[('message_id', '=', msg_dict['in_reply_to'])],
|
||||
order='create_date DESC, id DESC',
|
||||
limit=1)
|
||||
if msg_dict['references'] and not parent_ids:
|
||||
references_msg_id_list = tools.mail_header_msgid_re.findall(msg_dict['references'])
|
||||
parent_ids = self.env['mail.message'].search([('message_id', 'in', [x.strip() for x in references_msg_id_list])], limit=1)
|
||||
parent_ids = self.env['mail.message'].search(
|
||||
[('message_id', 'in', [x.strip() for x in references_msg_id_list])],
|
||||
order='create_date DESC, id DESC',
|
||||
limit=1)
|
||||
if parent_ids:
|
||||
msg_dict['parent_id'] = parent_ids.id
|
||||
msg_dict['is_internal'] = parent_ids.subtype_id and parent_ids.subtype_id.internal or False
|
||||
@@ -1849,6 +1855,13 @@ class MailThread(models.AbstractModel):
|
||||
if self._context.get('mail_post_autofollow') and partner_ids:
|
||||
self.message_subscribe(list(partner_ids))
|
||||
|
||||
# parent management, depending on ``_mail_flat_thread``
|
||||
# ``_mail_flat_thread`` True: no free message. If no parent, find the first
|
||||
# posted message and attach new message to it. If parent, get back to the first
|
||||
# ancestor and attach it. We don't keep hierarchy (one level of threading).
|
||||
# ``_mail_flat_thread`` False: free message = new thread (think of mailing lists).
|
||||
# If parent get up one level to try to flatten threads without completely
|
||||
# removing hierarchy.
|
||||
MailMessage_sudo = self.env['mail.message'].sudo()
|
||||
if self._mail_flat_thread and not parent_id:
|
||||
parent_message = MailMessage_sudo.search([('res_id', '=', self.id), ('model', '=', self._name), ('message_type', '!=', 'user_notification')], order="id ASC", limit=1)
|
||||
@@ -1856,16 +1869,17 @@ class MailThread(models.AbstractModel):
|
||||
# Note that with sudo we will match message with internal subtypes.
|
||||
parent_id = parent_message.id if parent_message else False
|
||||
elif parent_id:
|
||||
old_parent_id = parent_id
|
||||
parent_message = MailMessage_sudo.search([('id', '=', parent_id), ('parent_id', '!=', False)], limit=1)
|
||||
# avoid loops when finding ancestors
|
||||
processed_list = []
|
||||
if parent_message:
|
||||
new_parent_id = parent_message.parent_id and parent_message.parent_id.id
|
||||
while (new_parent_id and new_parent_id not in processed_list):
|
||||
processed_list.append(new_parent_id)
|
||||
parent_message = parent_message.parent_id
|
||||
parent_id = parent_message.id
|
||||
current_ancestor = MailMessage_sudo.search([('id', '=', parent_id), ('parent_id', '!=', False)])
|
||||
if self._mail_flat_thread:
|
||||
if current_ancestor:
|
||||
# avoid loops when finding ancestors
|
||||
processed_list = []
|
||||
while (current_ancestor.parent_id and current_ancestor.parent_id not in processed_list):
|
||||
processed_list.append(current_ancestor)
|
||||
current_ancestor = current_ancestor.parent_id
|
||||
parent_id = current_ancestor.id
|
||||
else:
|
||||
parent_id = current_ancestor.parent_id.id if current_ancestor.parent_id else parent_id
|
||||
|
||||
values = dict(msg_kwargs)
|
||||
values.update({
|
||||
@@ -2234,13 +2248,21 @@ class MailThread(models.AbstractModel):
|
||||
mail_subject = message.subject or (message.record_name and 'Re: %s' % message.record_name) # in cache, no queries
|
||||
# Replace new lines by spaces to conform to email headers requirements
|
||||
mail_subject = ' '.join((mail_subject or '').splitlines())
|
||||
# compute references: set references to the parent and add current message just to
|
||||
# have a fallback in case replies mess with Messsage-Id in the In-Reply-To (e.g. amazon
|
||||
# SES SMTP may replace Message-Id and In-Reply-To refers an internal ID not stored in Flectra)
|
||||
message_sudo = message.sudo()
|
||||
if message_sudo.parent_id:
|
||||
references = f'{message_sudo.parent_id.message_id} {message_sudo.message_id}'
|
||||
else:
|
||||
references = message_sudo.message_id
|
||||
# prepare notification mail values
|
||||
base_mail_values = {
|
||||
'mail_message_id': message.id,
|
||||
'mail_server_id': message.mail_server_id.id, # 2 query, check acces + read, may be useless, Falsy, when will it be used?
|
||||
'auto_delete': mail_auto_delete,
|
||||
# due to ir.rule, user have no right to access parent message if message is not published
|
||||
'references': message.parent_id.sudo().message_id if message.parent_id else False,
|
||||
'references': references,
|
||||
'subject': mail_subject,
|
||||
}
|
||||
base_mail_values = self._notify_by_email_add_values(base_mail_values)
|
||||
|
||||
@@ -756,6 +756,10 @@ class MailCase(MockEmail):
|
||||
self.assertMessageBusNotifications(message)
|
||||
|
||||
# check emails that should be sent (hint: mail.mail per group, email par recipient)
|
||||
email_values = {'body_content': mbody,
|
||||
'references_content': message.message_id}
|
||||
if message_info.get('email_values'):
|
||||
email_values.update(message_info['email_values'])
|
||||
for recipients in email_groups.values():
|
||||
partners = self.env['res.partner'].sudo().concat(*recipients)
|
||||
if all(p in mail_groups['failure'] for p in partners):
|
||||
@@ -772,12 +776,14 @@ class MailCase(MockEmail):
|
||||
partners, 'sent',
|
||||
author=message.author_id if message.author_id else message.email_from,
|
||||
mail_message=message,
|
||||
email_values={'body_content': mbody}
|
||||
email_values=email_values,
|
||||
)
|
||||
else:
|
||||
for recipient in partners:
|
||||
self.assertSentEmail(message.author_id if message.author_id else message.email_from, [recipient],
|
||||
email_values={'body_content': mbody})
|
||||
self.assertSentEmail(message.author_id if message.author_id else message.email_from,
|
||||
[recipient],
|
||||
**email_values
|
||||
)
|
||||
if not any(p for recipients in email_groups.values() for p in recipients):
|
||||
self.assertNoMail(partners, mail_message=message, author=message.author_id)
|
||||
|
||||
|
||||
Reference in new issue
Block a user