From 10d558ef2be2eb6915f0c52e8ea9561df91a9b1d Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 18 Jan 2019 11:41:43 +0000 Subject: [PATCH] [FIX] mail: failure notification - Debug mode, - Add multi-company to admin (user id 2), - Create new company (company 2) - Activate res.partner multi-company record rule - Create invoice - with first company (the default one) - with a customer having an email address that doesn't exist - Send a message in the thread, making sure the customer is in the follower - Wait for the message to bounce (red mail icon in the thread on the given message). - Change user to company 2 (in the dropdown menu next to the user dropdown menu in the upper right corner) - Refresh, access error, even in the app switcher. This is because Odoo tries to display in the notifications the email that failed, and crashes because the user doesn't have access to the partner of the email. We filter out the notifications related to objects that the user doesn't have access to. opw-1924359 closes odoo/odoo#30348 --- addons/mail/models/mail_message.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 394443e1ff2..677925b561c 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -534,6 +534,16 @@ class Message(models.Model): failures_infos = [] # for each channel, build the information header and include the logged partner information for message in self: + # Check if user has access to the record before displaying a notification about it. + # In case the user switches from one company to another, it might happen that he doesn't + # have access to the record related to the notification. In this case, we skip it. + if message.model and message.res_id: + record = self.env[message.model].browse(message.res_id) + try: + record.check_access_rights('read') + record.check_access_rule('read') + except AccessError: + continue info = { 'message_id': message.id, 'record_name': message.record_name,