From 8ec96343b5ccb5bb1c23761dda72b38ae0d7b0cb Mon Sep 17 00:00:00 2001 From: Denis Vermylen Date: Tue, 13 Sep 2022 17:13:46 +0000 Subject: [PATCH] [FIX] bus: fix websocket json routes Transform the /websocket/update_bus_presence route to type='json' which makes more sense as a POST than a get, seeing it does things with a parameter and doesn't return anything. Also fixes the _update_bus_presence method that leads to access errors when accessed from HTTP when the user is the public one (only portal/ internal users should update their presences). Part-of: odoo/odoo#100416 --- addons/bus/controllers/websocket.py | 3 ++- addons/bus/models/ir_websocket.py | 2 +- addons/mail/models/ir_websocket.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/bus/controllers/websocket.py b/addons/bus/controllers/websocket.py index f0121df7864..63048c088d5 100644 --- a/addons/bus/controllers/websocket.py +++ b/addons/bus/controllers/websocket.py @@ -42,9 +42,10 @@ class WebsocketController(Controller): notifications = request.env['bus.bus']._poll(channels, last) return {'channels': channels, 'notifications': notifications} - @route('/websocket/update_bus_presence', type='http', auth='public', cors='*') + @route('/websocket/update_bus_presence', type='json', auth='public', cors='*') def update_bus_presence(self, inactivity_period, im_status_ids_by_model): request.env['ir.websocket']._update_bus_presence(int(inactivity_period), im_status_ids_by_model) + return {} @route('/bus/websocket_worker_bundle', type='http', auth='public', cors='*') def get_websocket_worker_bundle(self): diff --git a/addons/bus/models/ir_websocket.py b/addons/bus/models/ir_websocket.py index 567abe1cd98..8f663d16b90 100644 --- a/addons/bus/models/ir_websocket.py +++ b/addons/bus/models/ir_websocket.py @@ -34,7 +34,7 @@ class IrWebsocket(models.AbstractModel): dispatch.subscribe(channels, data['last'], self.env.registry.db_name, wsrequest.ws) def _update_bus_presence(self, inactivity_period, im_status_ids_by_model): - if self.env.uid: + if self.env.user and not self.env.user._is_public(): self.env['bus.presence'].update( inactivity_period, identity_field='user_id', diff --git a/addons/mail/models/ir_websocket.py b/addons/mail/models/ir_websocket.py index 1461e3c55ac..733c756b44d 100644 --- a/addons/mail/models/ir_websocket.py +++ b/addons/mail/models/ir_websocket.py @@ -34,7 +34,7 @@ class IrWebsocket(models.AbstractModel): def _update_bus_presence(self, inactivity_period, im_status_ids_by_model): super()._update_bus_presence(inactivity_period, im_status_ids_by_model) - if not self.env.uid: + if not self.env.user or self.env.user._is_public(): # This method can either be called due to an http or a # websocket request. The request itself is necessary to # retrieve the current guest. Let's retrieve the proper