forked from DGNum/gestioCOF
Merge branch 'aureplop/clean_channels' into 'master'
Aureplop/clean channels Closes #67 See merge request !220
This commit is contained in:
commit
a725f8020c
2 changed files with 34 additions and 19 deletions
|
@ -1,26 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import (absolute_import, division,
|
||||
print_function, unicode_literals)
|
||||
from builtins import *
|
||||
from django.core.serializers.json import json, DjangoJSONEncoder
|
||||
|
||||
from channels import Group
|
||||
from channels.generic.websockets import JsonWebsocketConsumer
|
||||
|
||||
class KPsul(JsonWebsocketConsumer):
|
||||
|
||||
# Set to True if you want them, else leave out
|
||||
strict_ordering = False
|
||||
slight_ordering = False
|
||||
class DjangoJsonWebsocketConsumer(JsonWebsocketConsumer):
|
||||
"""Custom Json Websocket Consumer.
|
||||
|
||||
def connection_groups(self, **kwargs):
|
||||
return ['kfet.kpsul']
|
||||
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):
|
||||
pass
|
||||
"""Check permissions on connection."""
|
||||
if message.user.has_perms(self.perms_connect):
|
||||
super().connect(message, **kwargs)
|
||||
else:
|
||||
self.close()
|
||||
|
||||
def receive(self, content, **kwargs):
|
||||
pass
|
||||
|
||||
def disconnect(self, message, **kwargs):
|
||||
pass
|
||||
class KPsul(PermConsumerMixin, DjangoJsonWebsocketConsumer):
|
||||
groups = ['kfet.kpsul']
|
||||
perms_connect = ['kfet.is_team']
|
||||
|
|
|
@ -12,13 +12,13 @@ six==1.10.0
|
|||
unicodecsv==0.14.1
|
||||
icalendar==3.10
|
||||
django-bootstrap-form==3.2.1
|
||||
asgiref==0.14.0
|
||||
daphne==0.14.3
|
||||
asgi-redis==0.14.0
|
||||
asgiref==1.1.1
|
||||
daphne==1.2.0
|
||||
asgi-redis==1.3.0
|
||||
statistics==1.0.3.5
|
||||
future==0.15.2
|
||||
django-widget-tweaks==1.4.1
|
||||
git+https://git.eleves.ens.fr/cof-geek/django_custommail.git#egg=django_custommail
|
||||
ldap3
|
||||
git+https://github.com/Aureplop/channels.git#egg=channels
|
||||
channels==1.1.3
|
||||
python-dateutil
|
||||
|
|
Loading…
Reference in a new issue