outposts: handle disconnects without outpost better

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-25 11:46:28 +02:00
parent 6d3e067a2b
commit 58a4b20297
2 changed files with 8 additions and 6 deletions

View file

@ -50,7 +50,7 @@ class WebsocketMessage:
class OutpostConsumer(AuthJsonConsumer): class OutpostConsumer(AuthJsonConsumer):
"""Handler for Outposts that connect over websockets for health checks and live updates""" """Handler for Outposts that connect over websockets for health checks and live updates"""
outpost: Outpost outpost: Optional[Outpost] = None
last_uid: Optional[str] = None last_uid: Optional[str] = None
@ -95,6 +95,9 @@ class OutpostConsumer(AuthJsonConsumer):
uid = msg.args.get("uuid", self.channel_name) uid = msg.args.get("uuid", self.channel_name)
self.last_uid = uid self.last_uid = uid
if not self.outpost:
raise DenyConnection()
state = OutpostState.for_instance_uid(self.outpost, uid) state = OutpostState.for_instance_uid(self.outpost, uid)
if self.channel_name not in state.channel_ids: if self.channel_name not in state.channel_ids:
state.channel_ids.append(self.channel_name) state.channel_ids.append(self.channel_name)

View file

@ -3,7 +3,6 @@ from typing import Any, Optional
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.http.response import HttpResponseBadRequest from django.http.response import HttpResponseBadRequest
from django.utils.translation import gettext_lazy as _
from django.views import View from django.views import View
from structlog.stdlib import get_logger from structlog.stdlib import get_logger
@ -38,14 +37,14 @@ class UserInfoView(View):
# GitHub Compatibility Scopes are handeled differently, since they required custom paths # GitHub Compatibility Scopes are handeled differently, since they required custom paths
# Hence they don't exist as Scope objects # Hence they don't exist as Scope objects
github_scope_map = { github_scope_map = {
SCOPE_GITHUB_USER: _("GitHub Compatibility: Access your User Information"), SCOPE_GITHUB_USER: ("GitHub Compatibility: Access your User Information"),
SCOPE_GITHUB_USER_READ: _( SCOPE_GITHUB_USER_READ: (
"GitHub Compatibility: Access your User Information" "GitHub Compatibility: Access your User Information"
), ),
SCOPE_GITHUB_USER_EMAIL: _( SCOPE_GITHUB_USER_EMAIL: (
"GitHub Compatibility: Access you Email addresses" "GitHub Compatibility: Access you Email addresses"
), ),
SCOPE_GITHUB_ORG_READ: _("GitHub Compatibility: Access your Groups"), SCOPE_GITHUB_ORG_READ: ("GitHub Compatibility: Access your Groups"),
} }
for scope in scopes: for scope in scopes:
if scope in github_scope_map: if scope in github_scope_map: