Files
odoo_source/addons/web_editor/models/ir_websocket.py
T
Achraf (abz) a8d30764ae [FIX] web_editor: Fix MissingError traceback
A MissingError traceback that occurs in `_build_bus_channel_list` was
caught by Sentry. This error has been seen 1.3k times in the last 30
days from several customers.

The fix simply consists in checking if the document exists before
checking the rights on it.

Traceback:
```
MissingError: Record does not exist or has been deleted.
(Record: project.task(83,), User: 6)
  File "addons/bus/websocket.py", line 879, in _serve_forever
    req.serve_websocket_message(message)
  File "addons/bus/websocket.py", line 752, in serve_websocket_message
    service_model.retrying(
  File "odoo/service/model.py", line 134, in retrying
    result = func()
  File "addons/bus/websocket.py", line 767, in _serve_ir_websocket
    ir_websocket._subscribe(data)
  File "addons/bus/models/ir_websocket.py", line 38, in _subscribe
    channels = set(self._build_bus_channel_list(data['channels']))
  File "home/odoo/src/enterprise/16.0/spreadsheet_edition/models/ir_websocket.py", line 13, in _build_bus_channel_list
    return super()._build_bus_channel_list(channels)
  File "addons/web_editor/models/ir_websocket.py", line 33, in _build_bus_channel_list
    document.check_access_rule('read')
```

SAAS-K22 (sentry code)
opw-3086292

closes odoo/odoo#106982

X-original-commit: 9e4c5e427285b76000398476e9d923e7ea036a65
Signed-off-by: Achraf <abz@odoo.com>
2022-12-05 14:03:49 +01:00

42 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import re
from odoo import models
from odoo.exceptions import AccessDenied
class IrWebsocket(models.AbstractModel):
_inherit = 'ir.websocket'
def _build_bus_channel_list(self, channels):
if self.env.uid:
# Do not alter original list.
channels = list(channels)
for channel in channels:
if isinstance(channel, str):
match = re.match(r'editor_collaboration:(\w+(?:\.\w+)*):(\w+):(\d+)', channel)
if match:
model_name = match[1]
field_name = match[2]
res_id = int(match[3])
# Verify access to the edition channel.
if not self.env.user._is_internal():
raise AccessDenied()
document = self.env[model_name].browse([res_id])
if not document.exists():
continue
document.check_access_rights('read')
document.check_field_access_rights('read', [field_name])
document.check_access_rule('read')
document.check_access_rights('write')
document.check_field_access_rights('write', [field_name])
document.check_access_rule('write')
channels.append((self.env.registry.db_name, 'editor_collaboration', model_name, field_name, res_id))
return super()._build_bus_channel_list(channels)