mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Revert "Remove remaining traces of UserStub"
This reverts commit ab6b4c32254a20b940c489b8b5b56237433cc0f6.
This commit is contained in:
parent
16416463c6
commit
9a7c8c5842
5 changed files with 35 additions and 17 deletions
|
@ -80,7 +80,7 @@ module.exports = CollaboratorsHandler =
|
|||
result = []
|
||||
async.mapLimit members, 3,
|
||||
(member, cb) ->
|
||||
UserGetter.getUserById member.id, CollaboratorsHandler.USER_PROJECTION, (error, user) ->
|
||||
UserGetter.getUserOrUserStubById member.id, CollaboratorsHandler.USER_PROJECTION, (error, user) ->
|
||||
return cb(error) if error?
|
||||
if user?
|
||||
result.push { user: user, privilegeLevel: member.privilegeLevel }
|
||||
|
|
|
@ -27,18 +27,19 @@ module.exports = UserGetter =
|
|||
|
||||
db.users.find { _id: { $in: user_ids} }, projection, callback
|
||||
|
||||
getUserById: (user_id, projection, callback = (error, user) ->) ->
|
||||
getUserOrUserStubById: (user_id, projection, callback = (error, user) ->) ->
|
||||
try
|
||||
query = _id: ObjectId(user_id.toString())
|
||||
catch e
|
||||
return callback(new Error(e))
|
||||
db.users.findOne query, projection, (error, user) ->
|
||||
return callback(error) if error?
|
||||
callback(null, user)
|
||||
return callback(null, user) if user?
|
||||
db.userstubs.findOne query, projection, callback
|
||||
|
||||
[
|
||||
'getUser',
|
||||
'getUsers',
|
||||
'getUserById'
|
||||
'getUserOrUserStubById'
|
||||
].map (method) ->
|
||||
metrics.timeAsyncMethod UserGetter, method, 'mongo.UserGetter', logger
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Settings = require "settings-sharelatex"
|
||||
mongojs = require "mongojs"
|
||||
db = mongojs(Settings.mongo.url, ["projects", "users"])
|
||||
db = mongojs(Settings.mongo.url, ["projects", "users", "userstubs"])
|
||||
module.exports =
|
||||
db: db
|
||||
ObjectId: mongojs.ObjectId
|
||||
|
|
17
services/web/app/coffee/models/UserStub.coffee
Normal file
17
services/web/app/coffee/models/UserStub.coffee
Normal file
|
@ -0,0 +1,17 @@
|
|||
Settings = require "settings-sharelatex"
|
||||
mongoose = require('mongoose')
|
||||
Schema = mongoose.Schema
|
||||
ObjectId = Schema.ObjectId
|
||||
|
||||
UserStubSchema = new Schema
|
||||
email : { type : String, default : '' }
|
||||
first_name : { type : String, default : '' }
|
||||
last_name : { type : String, default : '' }
|
||||
overleaf : { id: { type: Number } }
|
||||
|
||||
conn = mongoose.createConnection(Settings.mongo.url, server: poolSize: 10)
|
||||
|
||||
UserStub = conn.model('UserStub', UserStubSchema)
|
||||
|
||||
model = mongoose.model 'UserStub', UserStubSchema
|
||||
exports.UserStub = UserStub
|
|
@ -97,12 +97,12 @@ describe "CollaboratorsHandler", ->
|
|||
{ id: "read-write-ref-2", privilegeLevel: "readAndWrite", source: 'invite' }
|
||||
{ id: "doesnt-exist", privilegeLevel: "readAndWrite", source: 'invite' }
|
||||
])
|
||||
@UserGetter.getUserById = sinon.stub()
|
||||
@UserGetter.getUserById.withArgs("read-only-ref-1").yields(null, { _id: "read-only-ref-1" })
|
||||
@UserGetter.getUserById.withArgs("read-only-ref-2").yields(null, { _id: "read-only-ref-2" })
|
||||
@UserGetter.getUserById.withArgs("read-write-ref-1").yields(null, { _id: "read-write-ref-1" })
|
||||
@UserGetter.getUserById.withArgs("read-write-ref-2").yields(null, { _id: "read-write-ref-2" })
|
||||
@UserGetter.getUserById.withArgs("doesnt-exist").yields(null, null)
|
||||
@UserGetter.getUserOrUserStubById = sinon.stub()
|
||||
@UserGetter.getUserOrUserStubById.withArgs("read-only-ref-1").yields(null, { _id: "read-only-ref-1" })
|
||||
@UserGetter.getUserOrUserStubById.withArgs("read-only-ref-2").yields(null, { _id: "read-only-ref-2" })
|
||||
@UserGetter.getUserOrUserStubById.withArgs("read-write-ref-1").yields(null, { _id: "read-write-ref-1" })
|
||||
@UserGetter.getUserOrUserStubById.withArgs("read-write-ref-2").yields(null, { _id: "read-write-ref-2" })
|
||||
@UserGetter.getUserOrUserStubById.withArgs("doesnt-exist").yields(null, null)
|
||||
@CollaboratorHandler.getMembersWithPrivilegeLevels @project_id, @callback
|
||||
|
||||
it "should return an array of members with their privilege levels", ->
|
||||
|
@ -125,12 +125,12 @@ describe "CollaboratorsHandler", ->
|
|||
{ id: "read-write-ref-2", privilegeLevel: "readAndWrite", source: 'invite' }
|
||||
{ id: "doesnt-exist", privilegeLevel: "readAndWrite", source: 'invite' }
|
||||
])
|
||||
@UserGetter.getUserById = sinon.stub()
|
||||
@UserGetter.getUserById.withArgs("read-only-ref-1").yields(null, { _id: "read-only-ref-1" })
|
||||
@UserGetter.getUserById.withArgs("read-only-ref-2").yields(null, { _id: "read-only-ref-2" })
|
||||
@UserGetter.getUserById.withArgs("read-write-ref-1").yields(null, { _id: "read-write-ref-1" })
|
||||
@UserGetter.getUserById.withArgs("read-write-ref-2").yields(null, { _id: "read-write-ref-2" })
|
||||
@UserGetter.getUserById.withArgs("doesnt-exist").yields(null, null)
|
||||
@UserGetter.getUserOrUserStubById = sinon.stub()
|
||||
@UserGetter.getUserOrUserStubById.withArgs("read-only-ref-1").yields(null, { _id: "read-only-ref-1" })
|
||||
@UserGetter.getUserOrUserStubById.withArgs("read-only-ref-2").yields(null, { _id: "read-only-ref-2" })
|
||||
@UserGetter.getUserOrUserStubById.withArgs("read-write-ref-1").yields(null, { _id: "read-write-ref-1" })
|
||||
@UserGetter.getUserOrUserStubById.withArgs("read-write-ref-2").yields(null, { _id: "read-write-ref-2" })
|
||||
@UserGetter.getUserOrUserStubById.withArgs("doesnt-exist").yields(null, null)
|
||||
@CollaboratorHandler.getInvitedMembersWithPrivilegeLevels @project_id, @callback
|
||||
|
||||
it "should return an array of invited members with their privilege levels", ->
|
||||
|
|
Loading…
Reference in a new issue