Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@channel_session_user
@catch_client_error
def new_poll(message):
if check_admin(message):
room = get_room_or_error(message["room"])
answers = json.loads(message["answer"])
answer_count = json.dumps([0] * len(answers))
poll = Poll.objects.create(
room=room,
question=message["question"],
answer=message["answer"],
answer_count=answer_count
)
if not message["question"]:
poll.question = 'poll_' + poll.hash_value
poll.save()
@channel_session_user
def ws_receive(message):
from awx.main.access import consumer_access
user = message.user
raw_data = message.content['text']
data = json.loads(raw_data)
xrftoken = data.get('xrftoken')
if (
not xrftoken or
XRF_KEY not in message.channel_session or
xrftoken != message.channel_session[XRF_KEY]
):
logger.error(
"access denied to channel, XRF mismatch for {}".format(user.username)
)
message.reply_channel.send({
@channel_session_user
@catch_client_error
def chat_leave(message):
room = get_room_or_error(message["room"], message.user)
if NOTIFY_USERS_ON_ENTER_OR_LEAVE_ROOMS:
room.send_message(None, message.user, MSG_TYPE_LEAVE)
room.websocket_group.discard(message.reply_channel)
message.channel_session['rooms'] = list(set(message.channel_session['rooms']).difference([room.id]))
message.reply_channel.send({
"text": json.dumps({
"leave": str(room.id),
}),
@channel_session_user
def ws_connect_forum(message):
"""Socket connect to forum"""
forum = get_params(message.content['query_string'])
message.channel_session['forum'] = forum
Group("forum-%s" % forum).add(message.reply_channel)
# Accept the connection request
message.reply_channel.send({"accept": True})
@channel_session_user
def ws_disconnect(message):
Group("user-%s" % message.user.pk).discard(message.reply_channel)
@channel_session_user
@catch_client_error
def get_slide(message):
room = get_room_or_error(message["room"])
slide = Slide.objects.get(room=room, now_id=message["id"])
hash_blob = javaHash(slide.md_blob)
if cache.ttl("%s/%s" % (message["room"], message["id"])) == 0:
cache.set(
"%s/%s" % (message["room"], message["id"]),
slide.md_blob,
timeout=60
)
cache.set(
"%s/%s/%s" % (message["room"], message["id"], hash_blob),
slide.md_blob,
timeout=60
@channel_session_user
@catch_client_error
def chat_leave(message):
# Reverse of join - remove them from everything.
room = get_room_or_error(message["room"], message.user)
# Send a "leave message" to the room if available
if NOTIFY_USERS_ON_ENTER_OR_LEAVE_ROOMS:
room.send_message(None, message.user, MSG_TYPE_LEAVE)
# discard room from group
room.websocket_group.discard(message.reply_channel)
# all the rooms in session - the room to be removed from session
message.channel_session['rooms'] = list(set(message.channel_session['rooms']).difference([room.id]))
# Send a message back that will prompt them to close the room
message.reply_channel.send({
"text": json.dumps({
@channel_session_user
def ws_message(message):
text = json.loads(message['text'])
Channel('websocket.events').send({
'reply_channel': message.reply_channel.name,
'event': text['event'],
'data': json.dumps(text['data'])
})
@channel_session_user
def ws_message(message):
if not message.user.is_authenticated():
return message.reply_channel.send({
"text": json.dumps({"error": "user not authenticated"})
})
data = json.loads(message["text"])
try:
task = getattr(tasks, data["task"])
except:
message.reply_channel.send({'text': {'event': 'task not found'}})
return
reply_channel = ReplyChannel(message.reply_channel.name)
task.delay(message.user.id, message.reply_channel.name, data["data"])
@channel_session_user
def ws_disconnect(message):
discard_groups(message)