remove unused websocket stuff
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
75f79ba951
commit
fc05f80951
|
@ -3,7 +3,7 @@ from channels.generic.websocket import JsonWebsocketConsumer
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
|
|
||||||
class MessageConsumer(JsonWebsocketConsumer):
|
class FrontendConsumer(JsonWebsocketConsumer):
|
||||||
"""Consumer which sends django.contrib.messages Messages over WS.
|
"""Consumer which sends django.contrib.messages Messages over WS.
|
||||||
channel_name is saved into cache with user_id, and when a add_message is called"""
|
channel_name is saved into cache with user_id, and when a add_message is called"""
|
||||||
|
|
||||||
|
@ -21,3 +21,19 @@ class MessageConsumer(JsonWebsocketConsumer):
|
||||||
def event_update(self, event: dict):
|
def event_update(self, event: dict):
|
||||||
"""Event handler which is called by Messages Storage backend"""
|
"""Event handler which is called by Messages Storage backend"""
|
||||||
self.send_json(event)
|
self.send_json(event)
|
||||||
|
|
||||||
|
# prefix = f"user_{self.request.session.session_key}_messages_"
|
||||||
|
# keys = cache.keys(f"{prefix}*")
|
||||||
|
# for key in keys:
|
||||||
|
# uid = key.replace(prefix, "")
|
||||||
|
# for message in messages:
|
||||||
|
# async_to_sync(self.channel.send)(
|
||||||
|
# uid,
|
||||||
|
# {
|
||||||
|
# "type": "event.update",
|
||||||
|
# "message_type": "message",
|
||||||
|
# "level": message.level_tag,
|
||||||
|
# "tags": message.tags,
|
||||||
|
# "message": message.message,
|
||||||
|
# },
|
||||||
|
# )
|
|
@ -1,5 +1,4 @@
|
||||||
"""Test utils"""
|
"""Test utils"""
|
||||||
from django.contrib.messages.middleware import MessageMiddleware
|
|
||||||
from django.contrib.sessions.middleware import SessionMiddleware
|
from django.contrib.sessions.middleware import SessionMiddleware
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
@ -21,7 +20,4 @@ def get_request(*args, user=None, **kwargs):
|
||||||
middleware = SessionMiddleware(dummy_get_response)
|
middleware = SessionMiddleware(dummy_get_response)
|
||||||
middleware.process_request(request)
|
middleware.process_request(request)
|
||||||
request.session.save()
|
request.session.save()
|
||||||
middleware = MessageMiddleware(dummy_get_response)
|
|
||||||
middleware.process_request(request)
|
|
||||||
request.session.save()
|
|
||||||
return request
|
return request
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
"""Channels Messages storage"""
|
|
||||||
from asgiref.sync import async_to_sync
|
|
||||||
from channels.layers import get_channel_layer
|
|
||||||
from django.contrib.messages.storage.base import BaseStorage, Message
|
|
||||||
from django.core.cache import cache
|
|
||||||
from django.http.request import HttpRequest
|
|
||||||
|
|
||||||
|
|
||||||
class ChannelsStorage(BaseStorage):
|
|
||||||
"""Send contrib.messages over websocket"""
|
|
||||||
|
|
||||||
def __init__(self, request: HttpRequest) -> None:
|
|
||||||
# pyright: reportGeneralTypeIssues=false
|
|
||||||
super().__init__(request)
|
|
||||||
self.channel = get_channel_layer()
|
|
||||||
|
|
||||||
def _get(self):
|
|
||||||
return [], True
|
|
||||||
|
|
||||||
def _store(self, messages: list[Message], response, *args, **kwargs):
|
|
||||||
prefix = f"user_{self.request.session.session_key}_messages_"
|
|
||||||
keys = cache.keys(f"{prefix}*")
|
|
||||||
for key in keys:
|
|
||||||
uid = key.replace(prefix, "")
|
|
||||||
for message in messages:
|
|
||||||
async_to_sync(self.channel.send)(
|
|
||||||
uid,
|
|
||||||
{
|
|
||||||
"type": "event.update",
|
|
||||||
"message_type": "message",
|
|
||||||
"level": message.level_tag,
|
|
||||||
"tags": message.tags,
|
|
||||||
"message": message.message,
|
|
||||||
},
|
|
||||||
)
|
|
|
@ -58,7 +58,6 @@ INSTALLED_APPS = [
|
||||||
"django.contrib.auth",
|
"django.contrib.auth",
|
||||||
"django.contrib.contenttypes",
|
"django.contrib.contenttypes",
|
||||||
"django.contrib.sessions",
|
"django.contrib.sessions",
|
||||||
"django.contrib.messages",
|
|
||||||
"django.contrib.staticfiles",
|
"django.contrib.staticfiles",
|
||||||
"django.contrib.humanize",
|
"django.contrib.humanize",
|
||||||
"authentik.admin",
|
"authentik.admin",
|
||||||
|
@ -219,7 +218,6 @@ MIDDLEWARE = [
|
||||||
"django.middleware.security.SecurityMiddleware",
|
"django.middleware.security.SecurityMiddleware",
|
||||||
"django.middleware.common.CommonMiddleware",
|
"django.middleware.common.CommonMiddleware",
|
||||||
"django.middleware.csrf.CsrfViewMiddleware",
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
"django.contrib.messages.middleware.MessageMiddleware",
|
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
"authentik.core.middleware.ImpersonateMiddleware",
|
"authentik.core.middleware.ImpersonateMiddleware",
|
||||||
"django_prometheus.middleware.PrometheusAfterMiddleware",
|
"django_prometheus.middleware.PrometheusAfterMiddleware",
|
||||||
|
@ -237,7 +235,6 @@ TEMPLATES = [
|
||||||
"django.template.context_processors.debug",
|
"django.template.context_processors.debug",
|
||||||
"django.template.context_processors.request",
|
"django.template.context_processors.request",
|
||||||
"django.contrib.auth.context_processors.auth",
|
"django.contrib.auth.context_processors.auth",
|
||||||
"django.contrib.messages.context_processors.messages",
|
|
||||||
"authentik.tenants.utils.context_processor",
|
"authentik.tenants.utils.context_processor",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
from channels.auth import AuthMiddlewareStack
|
from channels.auth import AuthMiddlewareStack
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
from authentik.core.ws.consumer import FrontendConsumer
|
||||||
from authentik.lib.sentry import SentryWSMiddleware
|
from authentik.lib.sentry import SentryWSMiddleware
|
||||||
from authentik.outposts.channels import OutpostConsumer
|
from authentik.outposts.channels import OutpostConsumer
|
||||||
from authentik.root.messages.consumer import MessageConsumer
|
|
||||||
|
|
||||||
websocket_urlpatterns = [
|
websocket_urlpatterns = [
|
||||||
path("ws/outpost/<uuid:pk>/", SentryWSMiddleware(OutpostConsumer.as_asgi())),
|
path("ws/outpost/<uuid:pk>/", SentryWSMiddleware(OutpostConsumer.as_asgi())),
|
||||||
path("ws/client/", AuthMiddlewareStack(SentryWSMiddleware(MessageConsumer.as_asgi()))),
|
path("ws/client/", AuthMiddlewareStack(SentryWSMiddleware(FrontendConsumer.as_asgi()))),
|
||||||
]
|
]
|
||||||
|
|
Reference in New Issue