overleaf/services/chat/app/coffee/Features/Authorization/AuthorizationManager.coffee
2014-08-15 10:50:36 +01:00

24 lines
983 B
CoffeeScript

WebApiManager = require "../WebApi/WebApiManager"
SocketManager = require "../Sockets/SocketManager"
module.exports = AuthorizationManager =
canClientJoinProjectRoom: (client, project_id, callback = (error, authorized) ->) ->
client.get "auth_token", (error, auth_token) ->
return callback(error) if error?
WebApiManager.getProjectCollaborators project_id, auth_token, (error, collaborators) ->
return callback(error) if error?
client.get "id", (error, user_id) ->
return callback(error) if error?
authorized = false
for collaborator in collaborators
if collaborator.id == user_id
authorized = true
break
callback null, authorized
canClientSendMessageToRoom: (client, room_id, callback = (error, authorized) ->) ->
SocketManager.isClientInRoom(client, room_id, callback)
canClientReadMessagesInRoom: (client, room_id, callback = (error, authorized) ->) ->
SocketManager.isClientInRoom(client, room_id, callback)