[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
This commit is contained in:
Nicolas Martinelli
2019-01-18 11:41:43 +00:00
parent 3c9cf1e753
commit 10d558ef2b
+10
View File
@@ -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,