summaryrefslogtreecommitdiff
path: root/addons/mail/models/mail_thread.py
diff options
context:
space:
mode:
authorAchraf (abz) <abz@odoo.com>2020-10-23 06:47:54 +0000
committerThibault Delavallée <tde@odoo.com>2021-01-06 17:03:53 +0000
commit79f27f640ccdd14f285a9dd9fc0ae770c992376f (patch)
treeea7e5b3c37a800fc5f7053f4244b197c4cd74c35 /addons/mail/models/mail_thread.py
parent5504ad189f66c63b930ae5a6f5838b8478ba28ec (diff)
[FIX] mail: send notification mail with right access link when using mail.thread
PURPOSE Notification may be sent using a generic mail.thread record, notably when sending user notifications. In that case links to view document are incorrect. HOW TO REPRODUCE Issue - Install "Approvals" - Submit new approval with you as "Request Owner" - Click on "View Approval Request" in your mailbox The link redirects to a 505 error Cause The model is not the correct one and the res_id is undefined Solution Specify the model and the res_id to _notify_get_action_link when creating the link with kwargs SPECIFICATIONS Propagate message value through various notification sub methods. That way we can rely on them if model seems void. Also limit values given as URL parameters to some white listed values. LINKS opw-2358846 Task ID-2379766 Followup of odoo/odoo#60998 Followup of odoo/odoo#61545 Closes odoo/odoo#63292 Closes odoo/enterprise#15585 closes odoo/odoo#64170 X-original-commit: 2b6d2b71f6c60bcf64db440473c88d1dc335acbf Related: odoo/enterprise#15588 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Co-authored-by: Achraf Ben Azzouz <abz@odoo.com> Co-authored-by: Thibault Delavallée <tde@odoo.com>
Diffstat (limited to 'addons/mail/models/mail_thread.py')
-rw-r--r--addons/mail/models/mail_thread.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py
index 1165caecbed..a581075cfbf 100644
--- a/addons/mail/models/mail_thread.py
+++ b/addons/mail/models/mail_thread.py
@@ -2212,7 +2212,7 @@ class MailThread(models.AbstractModel):
model = msg_vals.get('model') if msg_vals else message.model
model_name = model_description or (self._fallback_lang().env['ir.model']._get(model).display_name if model else False) # one query for display name
- recipients_groups_data = self._notify_classify_recipients(partners_data, model_name)
+ recipients_groups_data = self._notify_classify_recipients(partners_data, model_name, msg_vals=msg_vals)
if not recipients_groups_data:
return True
@@ -2486,22 +2486,23 @@ class MailThread(models.AbstractModel):
return hm
def _notify_get_action_link(self, link_type, **kwargs):
- local_kwargs = dict(kwargs) # do not modify in-place, modify copy instead
- base_params = {
+ """ Prepare link to an action: view document, follow document, ... """
+ params = {
'model': kwargs.get('model', self._name),
'res_id': kwargs.get('res_id', self.ids and self.ids[0] or False),
}
-
- local_kwargs.pop('message_id', None)
- local_kwargs.pop('model', None)
- local_kwargs.pop('res_id', None)
+ # whitelist accepted parameters: action (deprecated), token (assign), access_token
+ # (view), auth_signup_token and auth_login (for auth_signup support)
+ params.update(dict(
+ (key, value)
+ for key, value in kwargs.items()
+ if key in ('action', 'token', 'access_token', 'auth_signup_token', 'auth_login')
+ ))
if link_type in ['view', 'assign', 'follow', 'unfollow']:
- params = dict(base_params, **local_kwargs)
base_link = '/mail/%s' % link_type
elif link_type == 'controller':
- controller = local_kwargs.pop('controller')
- params = dict(base_params, **local_kwargs)
+ controller = kwargs.get('controller')
params.pop('model')
base_link = '%s' % controller
else:
@@ -2517,7 +2518,7 @@ class MailThread(models.AbstractModel):
return link
- def _notify_get_groups(self):
+ def _notify_get_groups(self, msg_vals=None):
""" Return groups used to classify recipients of a notification email.
Groups is a list of tuple containing of form (group_name, group_func,
group_data) where
@@ -2556,7 +2557,7 @@ class MailThread(models.AbstractModel):
)
]
- def _notify_classify_recipients(self, recipient_data, model_name):
+ def _notify_classify_recipients(self, recipient_data, model_name, msg_vals=None):
""" Classify recipients to be notified of a message in groups to have
specific rendering depending on their group. For example users could
have access to buttons customers should not have in their emails.
@@ -2587,10 +2588,10 @@ class MailThread(models.AbstractModel):
}]
only return groups with recipients
"""
-
- groups = self._notify_get_groups()
-
- access_link = self._notify_get_action_link('view')
+ # keep a local copy of msg_vals as it may be modified to include more information about groups or links
+ local_msg_vals = dict(msg_vals) if msg_vals else {}
+ groups = self._notify_get_groups(msg_vals=local_msg_vals)
+ access_link = self._notify_get_action_link('view', **local_msg_vals)
if model_name:
view_title = _('View %s', model_name)
@@ -2774,7 +2775,7 @@ class MailThread(models.AbstractModel):
values = {
'object': record,
'model_description': model_description,
- 'access_link': self._notify_get_action_link('view'),
+ 'access_link': record._notify_get_action_link('view'),
}
assignation_msg = view._render(values, engine='ir.qweb', minimal_qcontext=True)
assignation_msg = self.env['mail.render.mixin']._replace_local_links(assignation_msg)