django-websocket-redis icon indicating copy to clipboard operation
django-websocket-redis copied to clipboard

How to restrict channels based on database constraint?

Open ezheidtmann opened this issue 10 years ago • 1 comments

I suppose this counts as a support request.

I would like to use WS4REDIS_ALLOWED_CHANNELS to restrict the clients which can connect to a channel. The users' eligibility for the channel is based on permissions stored in the database. But the documentation for WS4REDIS_ALLOWED_CHANNELS states I can't use the DB:

Remember that this function is not allowed to perform any blocking requests, such as accessing the
database!

So what should I do? Can I return something like a promise? Or somehow else do async database queries?

ezheidtmann avatar Jun 26 '15 22:06 ezheidtmann

You should add the permission checks to the Django-Loop and then store them in Redis. This has some benefits: a) they expire themselves b) in the WS-loop you look up for that permission in Redis, using the session-id supplied by the client.

that should be rather easy to implement by inheriting from the subscriber classes.

jrief avatar Jun 27 '15 05:06 jrief