overleaf/services/chat/app/coffee/Features/Authorization/AuthorizationManager.coffee

25 lines
983 B
CoffeeScript
Raw Normal View History

2014-08-15 05:50:36 -04:00
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)