mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 03:26:43 -05:00
Merge pull request #7 from sharelatex/sk-missing-users
Handle missing users
This commit is contained in:
commit
cb8189deda
6 changed files with 113 additions and 17 deletions
|
@ -188,14 +188,15 @@ module.exports = UpdatesManager =
|
||||||
for update in updates
|
for update in updates
|
||||||
earliestUpdate = summarizedUpdates[summarizedUpdates.length - 1]
|
earliestUpdate = summarizedUpdates[summarizedUpdates.length - 1]
|
||||||
if earliestUpdate and earliestUpdate.meta.start_ts - update.meta.end_ts < @TIME_BETWEEN_DISTINCT_UPDATES
|
if earliestUpdate and earliestUpdate.meta.start_ts - update.meta.end_ts < @TIME_BETWEEN_DISTINCT_UPDATES
|
||||||
if update.meta.user?
|
# check if the user in this update is already present in the earliest update,
|
||||||
userExists = false
|
# if not, add them to the users list of the earliest update
|
||||||
for user in earliestUpdate.meta.users
|
userExists = false
|
||||||
if user.id == update.meta.user.id
|
for user in earliestUpdate.meta.users
|
||||||
userExists = true
|
if (!user and !update.meta.user) or (user?.id == update.meta.user?.id)
|
||||||
break
|
userExists = true
|
||||||
if !userExists
|
break
|
||||||
earliestUpdate.meta.users.push update.meta.user
|
if !userExists
|
||||||
|
earliestUpdate.meta.users.push update.meta.user
|
||||||
|
|
||||||
doc_id = update.doc_id.toString()
|
doc_id = update.doc_id.toString()
|
||||||
doc = earliestUpdate.docs[doc_id]
|
doc = earliestUpdate.docs[doc_id]
|
||||||
|
@ -220,11 +221,7 @@ module.exports = UpdatesManager =
|
||||||
newUpdate.docs[update.doc_id.toString()] =
|
newUpdate.docs[update.doc_id.toString()] =
|
||||||
fromV: update.v
|
fromV: update.v
|
||||||
toV: update.v
|
toV: update.v
|
||||||
|
newUpdate.meta.users.push update.meta.user
|
||||||
if update.meta.user?
|
|
||||||
newUpdate.meta.users.push update.meta.user
|
|
||||||
|
|
||||||
summarizedUpdates.push newUpdate
|
summarizedUpdates.push newUpdate
|
||||||
|
|
||||||
return summarizedUpdates
|
return summarizedUpdates
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ module.exports = WebApiManager =
|
||||||
if error?
|
if error?
|
||||||
return callback(error)
|
return callback(error)
|
||||||
if res.statusCode == 404
|
if res.statusCode == 404
|
||||||
|
logger.log url: url, "got 404 from web api"
|
||||||
return callback null, null
|
return callback null, null
|
||||||
if res.statusCode >= 200 and res.statusCode < 300
|
if res.statusCode >= 200 and res.statusCode < 300
|
||||||
return callback null, body
|
return callback null, body
|
||||||
|
|
|
@ -15,6 +15,7 @@ describe "Getting updates", ->
|
||||||
@now = Date.now()
|
@now = Date.now()
|
||||||
@to = @now
|
@to = @now
|
||||||
@user_id = ObjectId().toString()
|
@user_id = ObjectId().toString()
|
||||||
|
@deleted_user_id = 'deleted_user'
|
||||||
@doc_id = ObjectId().toString()
|
@doc_id = ObjectId().toString()
|
||||||
@project_id = ObjectId().toString()
|
@project_id = ObjectId().toString()
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ describe "Getting updates", ->
|
||||||
meta: { ts: @now - (9 - i) * @hours, user_id: @user_id }
|
meta: { ts: @now - (9 - i) * @hours, user_id: @user_id }
|
||||||
v: 2 * i + 2
|
v: 2 * i + 2
|
||||||
}
|
}
|
||||||
|
@updates[0].meta.user_id = @deleted_user_id
|
||||||
|
|
||||||
TrackChangesClient.pushRawUpdates @project_id, @doc_id, @updates, (error) =>
|
TrackChangesClient.pushRawUpdates @project_id, @doc_id, @updates, (error) =>
|
||||||
throw error if error?
|
throw error if error?
|
||||||
|
@ -91,7 +93,6 @@ describe "Getting updates", ->
|
||||||
users: [@user]
|
users: [@user]
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
describe "getting updates beyond the end of the database", ->
|
describe "getting updates beyond the end of the database", ->
|
||||||
before (done) ->
|
before (done) ->
|
||||||
TrackChangesClient.getUpdates @project_id, { before: @to - 8 * @hours + 1, min_count: 30 }, (error, body) =>
|
TrackChangesClient.getUpdates @project_id, { before: @to - 8 * @hours + 1, min_count: 30 }, (error, body) =>
|
||||||
|
@ -115,6 +116,5 @@ describe "Getting updates", ->
|
||||||
meta:
|
meta:
|
||||||
start_ts: @to - 9 * @hours - 2 * @minutes
|
start_ts: @to - 9 * @hours - 2 * @minutes
|
||||||
end_ts: @to - 9 * @hours
|
end_ts: @to - 9 * @hours
|
||||||
users: [@user]
|
users: [@user, null]
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ module.exports = MockWebApi =
|
||||||
projects: {}
|
projects: {}
|
||||||
|
|
||||||
getUser: (user_id, callback = (error) ->) ->
|
getUser: (user_id, callback = (error) ->) ->
|
||||||
callback null, @users[user_id]
|
callback null, @users[user_id] or null
|
||||||
|
|
||||||
getProject: (project_id, callback = (error, project) ->) ->
|
getProject: (project_id, callback = (error, project) ->) ->
|
||||||
callback null, @projects[project_id]
|
callback null, @projects[project_id]
|
||||||
|
|
|
@ -627,3 +627,91 @@ describe "UpdatesManager", ->
|
||||||
start_ts: @now
|
start_ts: @now
|
||||||
end_ts: @now + 50
|
end_ts: @now + 50
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
it "should include null user values", ->
|
||||||
|
result = @UpdatesManager._summarizeUpdates [{
|
||||||
|
doc_id: "doc-id-1"
|
||||||
|
meta:
|
||||||
|
user: @user_1
|
||||||
|
start_ts: @now + 20
|
||||||
|
end_ts: @now + 30
|
||||||
|
v: 5
|
||||||
|
}, {
|
||||||
|
doc_id: "doc-id-1"
|
||||||
|
meta:
|
||||||
|
user: null
|
||||||
|
start_ts: @now
|
||||||
|
end_ts: @now + 10
|
||||||
|
v: 4
|
||||||
|
}]
|
||||||
|
expect(result).to.deep.equal [{
|
||||||
|
docs:
|
||||||
|
"doc-id-1":
|
||||||
|
fromV: 4
|
||||||
|
toV: 5
|
||||||
|
meta:
|
||||||
|
users: [@user_1, null]
|
||||||
|
start_ts: @now
|
||||||
|
end_ts: @now + 30
|
||||||
|
}]
|
||||||
|
|
||||||
|
it "should include null user values, when the null is earlier in the updates list", ->
|
||||||
|
result = @UpdatesManager._summarizeUpdates [{
|
||||||
|
doc_id: "doc-id-1"
|
||||||
|
meta:
|
||||||
|
user: null
|
||||||
|
start_ts: @now
|
||||||
|
end_ts: @now + 10
|
||||||
|
v: 4
|
||||||
|
}, {
|
||||||
|
doc_id: "doc-id-1"
|
||||||
|
meta:
|
||||||
|
user: @user_1
|
||||||
|
start_ts: @now + 20
|
||||||
|
end_ts: @now + 30
|
||||||
|
v: 5
|
||||||
|
}]
|
||||||
|
expect(result).to.deep.equal [{
|
||||||
|
docs:
|
||||||
|
"doc-id-1":
|
||||||
|
fromV: 4
|
||||||
|
toV: 5
|
||||||
|
meta:
|
||||||
|
users: [null, @user_1]
|
||||||
|
start_ts: @now
|
||||||
|
end_ts: @now + 30
|
||||||
|
}]
|
||||||
|
|
||||||
|
it "should roll several null user values into one", ->
|
||||||
|
result = @UpdatesManager._summarizeUpdates [{
|
||||||
|
doc_id: "doc-id-1"
|
||||||
|
meta:
|
||||||
|
user: @user_1
|
||||||
|
start_ts: @now + 20
|
||||||
|
end_ts: @now + 30
|
||||||
|
v: 5
|
||||||
|
}, {
|
||||||
|
doc_id: "doc-id-1"
|
||||||
|
meta:
|
||||||
|
user: null
|
||||||
|
start_ts: @now
|
||||||
|
end_ts: @now + 10
|
||||||
|
v: 4
|
||||||
|
}, {
|
||||||
|
doc_id: "doc-id-1"
|
||||||
|
meta:
|
||||||
|
user: null
|
||||||
|
start_ts: @now + 2
|
||||||
|
end_ts: @now + 4
|
||||||
|
v: 4
|
||||||
|
}]
|
||||||
|
expect(result).to.deep.equal [{
|
||||||
|
docs:
|
||||||
|
"doc-id-1":
|
||||||
|
fromV: 4
|
||||||
|
toV: 5
|
||||||
|
meta:
|
||||||
|
users: [@user_1, null]
|
||||||
|
start_ts: @now
|
||||||
|
end_ts: @now + 30
|
||||||
|
}]
|
||||||
|
|
|
@ -72,6 +72,16 @@ describe "WebApiManager", ->
|
||||||
.calledWith(new Error("web returned failure status code: 500"))
|
.calledWith(new Error("web returned failure status code: 500"))
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
describe "when the user cannot be found", ->
|
||||||
|
beforeEach ->
|
||||||
|
@request.get = sinon.stub().callsArgWith(1, null, {statusCode: 404}, "nothing")
|
||||||
|
@WebApiManager.getUserInfo @user_id, @callback
|
||||||
|
|
||||||
|
it "should return a null value", ->
|
||||||
|
@callback
|
||||||
|
.calledWith(null, null)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
|
||||||
describe "getProjectDetails", ->
|
describe "getProjectDetails", ->
|
||||||
describe "successfully", ->
|
describe "successfully", ->
|
||||||
|
|
Loading…
Reference in a new issue