Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
close connection when not authenticated anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaswinkler committed Feb 3, 2021
1 parent e300ee0 commit c51fa60
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/paperless/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

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)(
Expand All @@ -20,4 +23,7 @@ def disconnect(self, close_code):
'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']))

0 comments on commit c51fa60

Please sign in to comment.