diff --git a/services/web/app/src/Features/Project/ProjectGetter.js b/services/web/app/src/Features/Project/ProjectGetter.js index a950160fe8..b5655a8ef5 100644 --- a/services/web/app/src/Features/Project/ProjectGetter.js +++ b/services/web/app/src/Features/Project/ProjectGetter.js @@ -14,6 +14,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const { db, ObjectId } = require('../../infrastructure/mongodb') +const { ObjectId: MongooseObjectId } = require('mongoose').mongo const OError = require('@overleaf/o-error') const metrics = require('metrics-sharelatex') const async = require('async') @@ -106,6 +107,8 @@ const ProjectGetter = { query = { _id: ObjectId(project_id) } } else if (project_id instanceof ObjectId) { query = { _id: project_id } + } else if (project_id instanceof MongooseObjectId) { + query = { _id: ObjectId(project_id.toString()) } } else if ( (project_id != null ? project_id.toString().length : undefined) === 24 ) { diff --git a/services/web/app/src/Features/User/UserGetter.js b/services/web/app/src/Features/User/UserGetter.js index a58866d26b..50c9778e1e 100644 --- a/services/web/app/src/Features/User/UserGetter.js +++ b/services/web/app/src/Features/User/UserGetter.js @@ -1,4 +1,5 @@ const { db, ObjectId } = require('../../infrastructure/mongodb') +const { ObjectId: MongooseObjectId } = require('mongoose').mongo const metrics = require('metrics-sharelatex') const logger = require('logger-sharelatex') const { promisifyAll } = require('../../util/promises') @@ -154,6 +155,8 @@ function normalizeQuery(query) { } if (typeof query === 'string') { return { _id: ObjectId(query) } + } else if (query instanceof MongooseObjectId) { + return { _id: ObjectId(query.toString()) } } else if (query instanceof ObjectId) { return { _id: query } } else if (Array.isArray(query)) { diff --git a/services/web/app/src/Features/User/UserUpdater.js b/services/web/app/src/Features/User/UserUpdater.js index d4f4ba4000..e99f639f33 100644 --- a/services/web/app/src/Features/User/UserUpdater.js +++ b/services/web/app/src/Features/User/UserUpdater.js @@ -1,6 +1,7 @@ const logger = require('logger-sharelatex') const OError = require('@overleaf/o-error') const { db, ObjectId } = require('../../infrastructure/mongodb') +const { ObjectId: MongooseObjectId } = require('mongoose').mongo const metrics = require('metrics-sharelatex') const async = require('async') const { callbackify, promisify } = require('util') @@ -196,6 +197,8 @@ const UserUpdater = { query = { _id: ObjectId(query) } } else if (query instanceof ObjectId) { query = { _id: query } + } else if (query instanceof MongooseObjectId) { + query = { _id: ObjectId(query.toString()) } } else if (typeof query._id === 'string') { query._id = ObjectId(query._id) } diff --git a/services/web/app/src/Features/UserMembership/UserMembershipViewModel.js b/services/web/app/src/Features/UserMembership/UserMembershipViewModel.js index b6d55d0386..f098613b08 100644 --- a/services/web/app/src/Features/UserMembership/UserMembershipViewModel.js +++ b/services/web/app/src/Features/UserMembership/UserMembershipViewModel.js @@ -12,6 +12,7 @@ */ let UserMembershipViewModel const { ObjectId } = require('mongodb') +const { ObjectId: MongooseObjectId } = require('mongoose').mongo const UserGetter = require('../User/UserGetter') module.exports = UserMembershipViewModel = { @@ -27,7 +28,12 @@ module.exports = UserMembershipViewModel = { if (callback == null) { callback = function(error, viewModel) {} } - if (!(userOrIdOrEmail instanceof ObjectId)) { + if ( + !( + userOrIdOrEmail instanceof ObjectId || + userOrIdOrEmail instanceof MongooseObjectId + ) + ) { // userOrIdOrEmail is a user or an email and can be parsed by #build return callback(null, UserMembershipViewModel.build(userOrIdOrEmail)) }