mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
connected user manager logic works correctly
This commit is contained in:
parent
d737197e95
commit
13aaf042d9
2 changed files with 12 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
||||||
_ = require("underscore")
|
_ = require("underscore")
|
||||||
async = require("async")
|
async = require("async")
|
||||||
Settings = require('settings-sharelatex')
|
Settings = require('settings-sharelatex')
|
||||||
|
logger = require("logger-sharelatex")
|
||||||
redis = require('redis')
|
redis = require('redis')
|
||||||
rclient = redis.createClient(Settings.redis.web.port, Settings.redis.web.host)
|
rclient = redis.createClient(Settings.redis.web.port, Settings.redis.web.host)
|
||||||
rclient.auth(Settings.redis.web.password)
|
rclient.auth(Settings.redis.web.password)
|
||||||
|
@ -20,8 +21,12 @@ module.exports =
|
||||||
(cb)->
|
(cb)->
|
||||||
rclient.sadd buildProjectSetKey(project_id), user_id, cb
|
rclient.sadd buildProjectSetKey(project_id), user_id, cb
|
||||||
(cb)->
|
(cb)->
|
||||||
rclient.setex buildUserKey(project_id, user_id), new Date(), ONE_HOUR_IN_S * 6, cb
|
ttl = ONE_HOUR_IN_S * 6
|
||||||
], callback
|
rclient.setex buildUserKey(project_id, user_id), ttl, new Date(), cb
|
||||||
|
], (err)->
|
||||||
|
if err?
|
||||||
|
logger.err err:err, project_id:project_id, user_id:user_id, "problem marking user as connected"
|
||||||
|
callback(err)
|
||||||
|
|
||||||
markUserAsDisconnected: (project_id, user_id, callback)->
|
markUserAsDisconnected: (project_id, user_id, callback)->
|
||||||
logger.log project_id:project_id, user_id:user_id, "marking user as disconnected"
|
logger.log project_id:project_id, user_id:user_id, "marking user as disconnected"
|
||||||
|
@ -32,8 +37,6 @@ module.exports =
|
||||||
rclient.del buildUserKey(project_id, user_id), cb
|
rclient.del buildUserKey(project_id, user_id), cb
|
||||||
], callback
|
], callback
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_getConnectedUser: (project_id, user_id, callback)->
|
_getConnectedUser: (project_id, user_id, callback)->
|
||||||
rclient.get buildUserKey(project_id, user_id), (err, result)->
|
rclient.get buildUserKey(project_id, user_id), (err, result)->
|
||||||
if !result?
|
if !result?
|
||||||
|
@ -45,8 +48,7 @@ module.exports =
|
||||||
|
|
||||||
getConnectedUsers: (project_id, callback)->
|
getConnectedUsers: (project_id, callback)->
|
||||||
self = @
|
self = @
|
||||||
rclient.get "connected_users_list:#{project_id}", (err, results)->
|
rclient.smembers buildProjectSetKey(project_id), (err, results)->
|
||||||
|
|
||||||
jobs = results.map (user_id)->
|
jobs = results.map (user_id)->
|
||||||
(cb)->
|
(cb)->
|
||||||
self._getConnectedUser(project_id, user_id, cb)
|
self._getConnectedUser(project_id, user_id, cb)
|
||||||
|
|
|
@ -23,6 +23,7 @@ describe "ConnectedUsersManager", ->
|
||||||
get: sinon.stub()
|
get: sinon.stub()
|
||||||
srem:sinon.stub()
|
srem:sinon.stub()
|
||||||
del:sinon.stub()
|
del:sinon.stub()
|
||||||
|
smembers:sinon.stub()
|
||||||
tk.freeze(new Date())
|
tk.freeze(new Date())
|
||||||
|
|
||||||
@ConnectedUsersManager = SandboxedModule.require modulePath, requires:
|
@ConnectedUsersManager = SandboxedModule.require modulePath, requires:
|
||||||
|
@ -45,7 +46,7 @@ describe "ConnectedUsersManager", ->
|
||||||
it "should set a key with the date and give it a ttl", (done)->
|
it "should set a key with the date and give it a ttl", (done)->
|
||||||
@ConnectedUsersManager.markUserAsConnected @project_id, @user_id, (err)=>
|
@ConnectedUsersManager.markUserAsConnected @project_id, @user_id, (err)=>
|
||||||
console.log @rClient.setex.args[0], "connected_user:#{@project_id}:#{@user_id}"
|
console.log @rClient.setex.args[0], "connected_user:#{@project_id}:#{@user_id}"
|
||||||
@rClient.setex.calledWith("connected_user:#{@project_id}:#{@user_id}", new Date(), 60 * 60 * 6).should.equal true
|
@rClient.setex.calledWith("connected_user:#{@project_id}:#{@user_id}", 60 * 60 * 6, new Date()).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should push the user_id on to the project list", (done)->
|
it "should push the user_id on to the project list", (done)->
|
||||||
|
@ -92,7 +93,7 @@ describe "ConnectedUsersManager", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@users = ["1234", "5678", "9123"]
|
@users = ["1234", "5678", "9123"]
|
||||||
@rClient.get.callsArgWith(1, null, @users)
|
@rClient.smembers.callsArgWith(1, null, @users)
|
||||||
@ConnectedUsersManager._getConnectedUser = sinon.stub()
|
@ConnectedUsersManager._getConnectedUser = sinon.stub()
|
||||||
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[0]).callsArgWith(2, null, {connected:true, user_id:@users[0]})
|
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[0]).callsArgWith(2, null, {connected:true, user_id:@users[0]})
|
||||||
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[1]).callsArgWith(2, null, {connected:false, user_id:@users[1]})
|
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[1]).callsArgWith(2, null, {connected:false, user_id:@users[1]})
|
||||||
|
|
Loading…
Reference in a new issue