From a06f4b6b285a18ed886b3c5dfe209e9f69279962 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Tue, 19 Sep 2017 16:16:39 +0100 Subject: [PATCH] Remove remaining traces of UserStub --- .../Collaborators/CollaboratorsHandler.coffee | 2 +- .../app/coffee/Features/User/UserGetter.coffee | 7 +++---- .../app/coffee/infrastructure/mongojs.coffee | 2 +- services/web/app/coffee/models/UserStub.coffee | 17 ----------------- .../CollaboratorsHandlerTests.coffee | 12 ++++++------ 5 files changed, 11 insertions(+), 29 deletions(-) delete mode 100644 services/web/app/coffee/models/UserStub.coffee diff --git a/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee b/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee index 09c9a7d74c..8c6209eb3f 100644 --- a/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee +++ b/services/web/app/coffee/Features/Collaborators/CollaboratorsHandler.coffee @@ -44,7 +44,7 @@ module.exports = CollaboratorsHandler = result = [] async.mapLimit members, 3, (member, cb) -> - UserGetter.getUserOrUserStubById member.id, CollaboratorsHandler.USER_PROJECTION, (error, user) -> + UserGetter.getUserById member.id, CollaboratorsHandler.USER_PROJECTION, (error, user) -> return cb(error) if error? if user? result.push { user: user, privilegeLevel: member.privilegeLevel } diff --git a/services/web/app/coffee/Features/User/UserGetter.coffee b/services/web/app/coffee/Features/User/UserGetter.coffee index 306fbc7a10..a7889fb798 100644 --- a/services/web/app/coffee/Features/User/UserGetter.coffee +++ b/services/web/app/coffee/Features/User/UserGetter.coffee @@ -27,19 +27,18 @@ module.exports = UserGetter = db.users.find { _id: { $in: user_ids} }, projection, callback - getUserOrUserStubById: (user_id, projection, callback = (error, user) ->) -> + getUserById: (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? - return callback(null, user) if user? - db.userstubs.findOne query, projection, callback + callback(null, user) [ 'getUser', 'getUsers', - 'getUserOrUserStubById' + 'getUserById' ].map (method) -> metrics.timeAsyncMethod UserGetter, method, 'mongo.UserGetter', logger diff --git a/services/web/app/coffee/infrastructure/mongojs.coffee b/services/web/app/coffee/infrastructure/mongojs.coffee index f1ed213435..15eb560a67 100644 --- a/services/web/app/coffee/infrastructure/mongojs.coffee +++ b/services/web/app/coffee/infrastructure/mongojs.coffee @@ -1,6 +1,6 @@ Settings = require "settings-sharelatex" mongojs = require "mongojs" -db = mongojs(Settings.mongo.url, ["projects", "users", "userstubs"]) +db = mongojs(Settings.mongo.url, ["projects", "users"]) module.exports = db: db ObjectId: mongojs.ObjectId diff --git a/services/web/app/coffee/models/UserStub.coffee b/services/web/app/coffee/models/UserStub.coffee deleted file mode 100644 index c37a7dfb30..0000000000 --- a/services/web/app/coffee/models/UserStub.coffee +++ /dev/null @@ -1,17 +0,0 @@ -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 diff --git a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee index c1f3057f2b..8f8720aaf2 100644 --- a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsHandlerTests.coffee @@ -80,12 +80,12 @@ describe "CollaboratorsHandler", -> { id: "read-write-ref-2", privilegeLevel: "readAndWrite" } { id: "doesnt-exist", privilegeLevel: "readAndWrite" } ]) - @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) + @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) @CollaboratorHandler.getMembersWithPrivilegeLevels @project_id, @callback it "should return an array of members with their privilege levels", ->