kfet.open
kfet.open app - Base data (raw_open, last_update...) is stored and shared through cache system. - 2 websockets groups: one for team users, one for other users. - UI is initialized and kept up-to-date with WS. - raw_open and force_close can be updated with standard HTTP requests. At this time, there isn't any restriction on raw_open view. Common sense tell us to change this behavior. Misc - Clean channels routing. - 'PermConsumerMixin': user who sent the message is available as argument in connection_groups method, which returns groups to which the user should be appended on websocket connection (and discarded on disconnection). - New kfet.utils module: should be used for mixins, whatever is useful and not concerns the kfet app. - Clean JS dependencies.
This commit is contained in:
parent
2381af92e3
commit
b8110c11a4
37 changed files with 852 additions and 404 deletions
|
@ -1,53 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.core.serializers.json import json, DjangoJSONEncoder
|
||||
|
||||
from channels.generic.websockets import JsonWebsocketConsumer
|
||||
|
||||
|
||||
class DjangoJsonWebsocketConsumer(JsonWebsocketConsumer):
|
||||
"""Custom Json Websocket Consumer.
|
||||
|
||||
Encode to JSON with DjangoJSONEncoder.
|
||||
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def encode_json(cls, content):
|
||||
return json.dumps(content, cls=DjangoJSONEncoder)
|
||||
|
||||
|
||||
class PermConsumerMixin(object):
|
||||
"""Add support to check permissions on Consumers.
|
||||
|
||||
Attributes:
|
||||
perms_connect (list): Required permissions to connect to this
|
||||
consumer.
|
||||
|
||||
"""
|
||||
http_user = True # Enable message.user
|
||||
perms_connect = []
|
||||
|
||||
def connect(self, message, **kwargs):
|
||||
"""Check permissions on connection."""
|
||||
if message.user.has_perms(self.perms_connect):
|
||||
super().connect(message, **kwargs)
|
||||
else:
|
||||
self.close()
|
||||
|
||||
|
||||
class KfetOpen(JsonWebsocketConsumer):
|
||||
def connection_groups(self, **kwargs):
|
||||
return ['kfet.is_open']
|
||||
|
||||
def connect(self, message, **kwargs):
|
||||
pass
|
||||
|
||||
def receive(self, content, **kwargs):
|
||||
pass
|
||||
|
||||
def disconnect(self, message, **kwargs):
|
||||
pass
|
||||
from .utils import DjangoJsonWebsocketConsumer, PermConsumerMixin
|
||||
|
||||
|
||||
class KPsul(PermConsumerMixin, DjangoJsonWebsocketConsumer):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue