summaryrefslogtreecommitdiff
path: root/addons/mail/models/mail_thread.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-08-26 13:54:30 +0000
committerThibault Delavallée <tde@odoo.com>2020-08-28 12:43:11 +0000
commitfe27f9fe0cf9581c15a2a9e45125abe82dd303ad (patch)
treec3cccfed270554d77ceb88a127f4f27c8dbcc2e8 /addons/mail/models/mail_thread.py
parent42910ce25f06a31af3cfbc8d5d41e443ee754c34 (diff)
[IMP] mail: subscribe creator of document through mail gateway if not superuser
Document creation or update is still done without auto subscribe. Indeed user running mailgateway or owning alias is not necessarily linked to the email author. That way we avoid auto subscription of irrelevant people. Posting message based on incoming email is now allowing auto subscription if there is an author found during email parsing. We also ensure this author is not root, to be sure he is not added in followers of documents. LINKS Task ID-2326281 PR odoo/odoo#56560 Closes odoo/odoo#38383
Diffstat (limited to 'addons/mail/models/mail_thread.py')
-rw-r--r--addons/mail/models/mail_thread.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py
index 44527232803..24adb15b450 100644
--- a/addons/mail/models/mail_thread.py
+++ b/addons/mail/models/mail_thread.py
@@ -1027,6 +1027,7 @@ class MailThread(models.AbstractModel):
thread_id = False
for model, thread_id, custom_values, user_id, alias in routes or ():
subtype_id = False
+ related_user = self.env['res.users'].browse(user_id)
Model = self.env[model].with_context(mail_create_nosubscribe=True, mail_create_nolog=True)
if not (thread_id and hasattr(Model, 'message_update') or hasattr(Model, 'message_new')):
raise ValueError(
@@ -1036,7 +1037,7 @@ class MailThread(models.AbstractModel):
# disabled subscriptions during message_new/update to avoid having the system user running the
# email gateway become a follower of all inbound messages
- ModelCtx = Model.with_user(user_id).sudo()
+ ModelCtx = Model.with_user(related_user).sudo()
if thread_id and hasattr(ModelCtx, 'message_update'):
thread = ModelCtx.browse(thread_id)
thread.message_update(message_dict)
@@ -1069,6 +1070,9 @@ class MailThread(models.AbstractModel):
if thread._name == 'mail.thread': # message with parent_id not linked to record
new_msg = thread.message_notify(**post_params)
else:
+ # parsing should find an author independently of user running mail gateway, and ensure it is not odoobot
+ partner_from_found = message_dict.get('author_id') and message_dict['author_id'] != self.env['ir.model.data'].xmlid_to_res_id('base.partner_root')
+ thread = thread.with_context(mail_create_nosubscribe=not partner_from_found)
new_msg = thread.message_post(**post_params)
if new_msg and original_partner_ids: