From ba3c8308b369a329f1e92e4419f6d8ad697c667f Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Wed, 3 Feb 2021 20:44:10 +0100 Subject: [PATCH] websocket authentication --- src/paperless/consumers.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/paperless/consumers.py b/src/paperless/consumers.py index 21a0e3ede..b3d31b402 100644 --- a/src/paperless/consumers.py +++ b/src/paperless/consumers.py @@ -1,14 +1,19 @@ import json from asgiref.sync import async_to_sync +from channels.exceptions import DenyConnection, AcceptConnection from channels.generic.websocket import WebsocketConsumer class StatusConsumer(WebsocketConsumer): + def connect(self): - self.accept() - async_to_sync(self.channel_layer.group_add)( - 'status_updates', self.channel_name) + if not self.scope['user'].is_authenticated: + raise DenyConnection() + else: + async_to_sync(self.channel_layer.group_add)( + 'status_updates', self.channel_name) + raise AcceptConnection() def disconnect(self, close_code): async_to_sync(self.channel_layer.group_discard)(