From c51fa6017235fe14b757a6d536f74064cff6c578 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Wed, 3 Feb 2021 21:53:39 +0100 Subject: [PATCH] close connection when not authenticated anymore. --- src/paperless/consumers.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/paperless/consumers.py b/src/paperless/consumers.py index b3d31b402..45f6ad9c5 100644 --- a/src/paperless/consumers.py +++ b/src/paperless/consumers.py @@ -7,8 +7,11 @@ from channels.generic.websocket import WebsocketConsumer class StatusConsumer(WebsocketConsumer): + def _authenticated(self): + return 'user' in self.scope and self.scope['user'].is_authenticated + def connect(self): - if not self.scope['user'].is_authenticated: + if not self._authenticated(): raise DenyConnection() else: async_to_sync(self.channel_layer.group_add)( @@ -20,4 +23,7 @@ class StatusConsumer(WebsocketConsumer): 'status_updates', self.channel_name) def status_update(self, event): - self.send(json.dumps(event['data'])) + if not self._authenticated(): + self.close() + else: + self.send(json.dumps(event['data']))