mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add in leaveDoc end point
This commit is contained in:
parent
eb8ccc0298
commit
8b923d2fda
3 changed files with 39 additions and 5 deletions
|
@ -63,3 +63,12 @@ module.exports = Router =
|
|||
else
|
||||
callback(null, args...)
|
||||
|
||||
client.on "leaveDoc", (doc_id, callback) ->
|
||||
WebsocketController.leaveDoc client, doc_id, (err, args...) ->
|
||||
if err?
|
||||
Router._getClientData client, (_, client) ->
|
||||
logger.error {err, client, doc_id}, "server side error in leaveDoc"
|
||||
# Don't return raw error to prevent leaking server side info
|
||||
return callback {message: "Something went wrong"}
|
||||
else
|
||||
callback(null, args...)
|
|
@ -34,9 +34,8 @@ module.exports = WebsocketController =
|
|||
callback null, project, privilegeLevel, WebsocketController.PROTOCOL_VERSION
|
||||
|
||||
joinDoc: (client, doc_id, fromVersion = -1, callback = (error, doclines, version, ops) ->) ->
|
||||
client.get "user_id", (error, user_id) ->
|
||||
client.get "project_id", (error, project_id) ->
|
||||
logger.log {user_id, project_id, doc_id, fromVersion, client_id: client.id}, "client joining doc"
|
||||
WebsocketController._getClientData client, (error, {client_id, user_id, project_id}) ->
|
||||
logger.log {user_id, project_id, doc_id, fromVersion, client_id}, "client joining doc"
|
||||
|
||||
AuthorizationManager.assertClientCanViewProject client, (error) ->
|
||||
return callback(error) if error?
|
||||
|
@ -58,3 +57,15 @@ module.exports = WebsocketController =
|
|||
client.join(doc_id)
|
||||
callback null, escapedLines, version, ops
|
||||
|
||||
leaveDoc: (client, doc_id, callback = (error) ->) ->
|
||||
WebsocketController._getClientData client, (error, {client_id, user_id, project_id}) ->
|
||||
logger.log {user_id, project_id, doc_id, client_id}, "client leaving doc"
|
||||
client.leave doc_id
|
||||
callback()
|
||||
|
||||
# Only used in logging.
|
||||
_getClientData: (client, callback = (error, data) ->) ->
|
||||
client.get "user_id", (error, user_id) ->
|
||||
client.get "project_id", (error, project_id) ->
|
||||
callback null, {client_id: client.id, project_id, user_id}
|
||||
|
|
@ -23,6 +23,7 @@ describe 'WebsocketController', ->
|
|||
set: sinon.stub()
|
||||
get: (param, cb) -> cb null, @params[param]
|
||||
join: sinon.stub()
|
||||
leave: sinon.stub()
|
||||
@WebsocketController = SandboxedModule.require modulePath, requires:
|
||||
"./WebApiManager": @WebApiManager = {}
|
||||
"./AuthorizationManager": @AuthorizationManager = {}
|
||||
|
@ -154,3 +155,16 @@ describe 'WebsocketController', ->
|
|||
|
||||
it "should not call the DocumentUpdaterManager", ->
|
||||
@DocumentUpdaterManager.getDocument.called.should.equal false
|
||||
|
||||
describe "leaveDoc", ->
|
||||
beforeEach ->
|
||||
@doc_id = "doc-id-123"
|
||||
@client.params.project_id = @project_id
|
||||
@WebsocketController.leaveDoc @client, @doc_id, @callback
|
||||
|
||||
it "should remove the client from the doc_id room", ->
|
||||
@client.leave
|
||||
.calledWith(@doc_id).should.equal true
|
||||
|
||||
it "should call the callback", ->
|
||||
@callback.called.should.equal true
|
Loading…
Reference in a new issue