AuthorizationManager.coffee 983 B

123456789101112131415161718192021222324
  1. WebApiManager = require "../WebApi/WebApiManager"
  2. SocketManager = require "../Sockets/SocketManager"
  3. module.exports = AuthorizationManager =
  4. canClientJoinProjectRoom: (client, project_id, callback = (error, authorized) ->) ->
  5. client.get "auth_token", (error, auth_token) ->
  6. return callback(error) if error?
  7. WebApiManager.getProjectCollaborators project_id, auth_token, (error, collaborators) ->
  8. return callback(error) if error?
  9. client.get "id", (error, user_id) ->
  10. return callback(error) if error?
  11. authorized = false
  12. for collaborator in collaborators
  13. if collaborator.id == user_id
  14. authorized = true
  15. break
  16. callback null, authorized
  17. canClientSendMessageToRoom: (client, room_id, callback = (error, authorized) ->) ->
  18. SocketManager.isClientInRoom(client, room_id, callback)
  19. canClientReadMessagesInRoom: (client, room_id, callback = (error, authorized) ->) ->
  20. SocketManager.isClientInRoom(client, room_id, callback)