diff --git a/package-lock.json b/package-lock.json index f7c2b18b76f..eb8a56ed6d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -99,10 +99,10 @@ "moment": "^2.19.2", "mongodb-memory-server-global": "^9.1.8", "mongodb-uri": "^0.9.7", - "mongoose": "^6.12.3", - "mongoose-delete": "^0.5.4", + "mongoose": "^8.5.1", + "mongoose-delete": "^1.0.2", "mongoose-id-validator": "^0.6.0", - "mongoose-lean-virtuals": "^0.8.1", + "mongoose-lean-virtuals": "^0.9.1", "mongoose-shortid-nodeps": "git://github.com/leeroybrun/mongoose-shortid-nodeps.git", "moodle-client": "^0.5.2", "nanoid": "^3.3.4", @@ -5879,9 +5879,9 @@ } }, "node_modules/@mongodb-js/saslprep": { - "version": "1.1.0", - "license": "MIT", - "optional": true, + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.8.tgz", + "integrity": "sha512-qKwC/M/nNNaKUBMQ0nuzm47b7ZYWQHN3pcXq4IIcoSBc2hOIrflAxJduIvvqmhoz3gR2TacTAs8vlsCVPkiEdQ==", "dependencies": { "sparse-bitfield": "^3.0.3" } @@ -18064,8 +18064,9 @@ "license": "MIT" }, "node_modules/kareem": { - "version": "2.5.1", - "license": "Apache-2.0", + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.3.tgz", + "integrity": "sha512-C3iHfuGUXK2u8/ipq9LfjFfXFxAZMQJJq7vLS45r3D9Y2xQ/m4S8zaR4zMLFWh9AsNPXmcFfUDhTEO8UIC/V6Q==", "engines": { "node": ">=12.0.0" } @@ -18682,8 +18683,7 @@ }, "node_modules/memory-pager": { "version": "1.5.0", - "license": "MIT", - "optional": true + "license": "MIT" }, "node_modules/merge": { "version": "2.1.1", @@ -19163,19 +19163,20 @@ } }, "node_modules/mongoose": { - "version": "6.12.3", - "license": "MIT", + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.5.1.tgz", + "integrity": "sha512-OhVcwVl91A1G6+XpjDcpkGP7l7ikZkxa0DylX7NT/lcEqAjggzSdqDxb48A+xsDxqNAr0ntSJ1yiE3+KJTOd5Q==", "dependencies": { - "bson": "^4.7.2", - "kareem": "2.5.1", - "mongodb": "4.17.1", + "bson": "^6.7.0", + "kareem": "2.6.3", + "mongodb": "6.7.0", "mpath": "0.9.0", - "mquery": "4.0.3", + "mquery": "5.0.0", "ms": "2.1.3", - "sift": "16.0.1" + "sift": "17.1.3" }, "engines": { - "node": ">=12.0.0" + "node": ">=16.20.1" }, "funding": { "type": "opencollective", @@ -19183,10 +19184,11 @@ } }, "node_modules/mongoose-delete": { - "version": "0.5.4", - "license": "MIT", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/mongoose-delete/-/mongoose-delete-1.0.2.tgz", + "integrity": "sha512-W+p9ULLiYHcEz77wQECp6gNnh2NcXf30KRIE3nAyjjsStqmBKJDL5eXTnX0xerGG2gCGx6mI7bO3+ch88tQ+tg==", "peerDependencies": { - "mongoose": "4.x || 5.x || 6.x" + "mongoose": "5.x || 6.x || 7.x || 8.x" } }, "node_modules/mongoose-id-validator": { @@ -19198,8 +19200,9 @@ } }, "node_modules/mongoose-lean-virtuals": { - "version": "0.8.1", - "license": "Apache 2.0", + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/mongoose-lean-virtuals/-/mongoose-lean-virtuals-0.9.1.tgz", + "integrity": "sha512-jx4rhXuaQPam/lwef3z/FfYHlKdbFkDr9Qb7JEMeoa7y4pOuyJ83RkcNL25HRaoi4Bt71zKmV1cuJdv243t9aA==", "dependencies": { "array.prototype.flat": "1.2.3", "mpath": "^0.8.4" @@ -19230,20 +19233,74 @@ "mongoose": ">= 4.4.0" } }, + "node_modules/mongoose/node_modules/@types/whatwg-url": { + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz", + "integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==", + "dependencies": { + "@types/webidl-conversions": "*" + } + }, + "node_modules/mongoose/node_modules/bson": { + "version": "6.8.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.8.0.tgz", + "integrity": "sha512-iOJg8pr7wq2tg/zSlCCHMi3hMm5JTOxLTagf3zxhcenHsFp+c6uOs6K7W5UE7A4QIJGtqh/ZovFNMP4mOPJynQ==", + "engines": { + "node": ">=16.20.1" + } + }, "node_modules/mongoose/node_modules/mongodb": { - "version": "4.17.1", - "license": "Apache-2.0", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.7.0.tgz", + "integrity": "sha512-TMKyHdtMcO0fYBNORiYdmM25ijsHs+Njs963r4Tro4OQZzqYigAzYQouwWRg4OIaiLRUEGUh/1UAcH5lxdSLIA==", "dependencies": { - "bson": "^4.7.2", - "mongodb-connection-string-url": "^2.6.0", - "socks": "^2.7.1" + "@mongodb-js/saslprep": "^1.1.5", + "bson": "^6.7.0", + "mongodb-connection-string-url": "^3.0.0" }, "engines": { - "node": ">=12.9.0" + "node": ">=16.20.1" }, - "optionalDependencies": { - "@aws-sdk/credential-providers": "^3.186.0", - "@mongodb-js/saslprep": "^1.1.0" + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.188.0", + "@mongodb-js/zstd": "^1.1.0", + "gcp-metadata": "^5.2.0", + "kerberos": "^2.0.1", + "mongodb-client-encryption": ">=6.0.0 <7", + "snappy": "^7.2.2", + "socks": "^2.7.1" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/mongoose/node_modules/mongodb-connection-string-url": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.1.tgz", + "integrity": "sha512-XqMGwRX0Lgn05TDB4PyG2h2kKO/FfWJyCzYQbIhXUxz7ETt0I/FqHjUeqj37irJ+Dl1ZtU82uYyj14u2XsZKfg==", + "dependencies": { + "@types/whatwg-url": "^11.0.2", + "whatwg-url": "^13.0.0" } }, "node_modules/mongoose/node_modules/mpath": { @@ -19257,6 +19314,29 @@ "version": "2.1.3", "license": "MIT" }, + "node_modules/mongoose/node_modules/tr46": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-4.1.1.tgz", + "integrity": "sha512-2lv/66T7e5yNyhAAC4NaKe5nVavzuGJQVVtRYLyQ2OI8tsJ61PMLlelehb0wi2Hx6+hT/OJUWZcw8MjlSRnxvw==", + "dependencies": { + "punycode": "^2.3.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/mongoose/node_modules/whatwg-url": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-13.0.0.tgz", + "integrity": "sha512-9WWbymnqj57+XEuqADHrCJ2eSXzn8WXIW/YSGaZtb2WKAInQ6CHfaUUcTyyver0p8BDg5StLQq8h1vtZuwmOig==", + "dependencies": { + "tr46": "^4.1.1", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/moodle-client": { "version": "0.5.2", "license": "BSD-2-Clause", @@ -19434,13 +19514,14 @@ } }, "node_modules/mquery": { - "version": "4.0.3", - "license": "MIT", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", + "integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==", "dependencies": { "debug": "4.x" }, "engines": { - "node": ">=12.0.0" + "node": ">=14.0.0" } }, "node_modules/mri": { @@ -22963,8 +23044,9 @@ } }, "node_modules/sift": { - "version": "16.0.1", - "license": "MIT" + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==" }, "node_modules/signal-exit": { "version": "3.0.7", @@ -23225,7 +23307,6 @@ "node_modules/sparse-bitfield": { "version": "3.0.3", "license": "MIT", - "optional": true, "dependencies": { "memory-pager": "^1.0.2" } diff --git a/package.json b/package.json index 64071a17d9f..4cf11958833 100644 --- a/package.json +++ b/package.json @@ -215,10 +215,10 @@ "moment": "^2.19.2", "mongodb-memory-server-global": "^9.1.8", "mongodb-uri": "^0.9.7", - "mongoose": "^6.12.3", - "mongoose-delete": "^0.5.4", + "mongoose": "^8.5.1", + "mongoose-delete": "^1.0.2", "mongoose-id-validator": "^0.6.0", - "mongoose-lean-virtuals": "^0.8.1", + "mongoose-lean-virtuals": "^0.9.1", "mongoose-shortid-nodeps": "git://github.com/leeroybrun/mongoose-shortid-nodeps.git", "moodle-client": "^0.5.2", "nanoid": "^3.3.4", diff --git a/src/services/consent/services/consent.deprecated.js b/src/services/consent/services/consent.deprecated.js index 89104070ee9..5e89332f379 100644 --- a/src/services/consent/services/consent.deprecated.js +++ b/src/services/consent/services/consent.deprecated.js @@ -31,7 +31,7 @@ class ConsentService { // check for _basonType is need for internal request // and because of id could also include an $in or simular // eslint-disable-next-line no-underscore-dangle - if (typeof userId === 'string' || userId._bsontype === 'ObjectID') { + if (typeof userId === 'string' || userId._bsontype === 'ObjectId') { const user = await this.modelService.get(userId); return { total: 1, diff --git a/src/services/fileStorage/proxy-service.js b/src/services/fileStorage/proxy-service.js index eaaefbb4071..89e350904f1 100644 --- a/src/services/fileStorage/proxy-service.js +++ b/src/services/fileStorage/proxy-service.js @@ -322,7 +322,7 @@ const fileStorageService = { } return permissionPromise() - .then(() => FileModel.update({ _id }, update).exec()) + .then(() => FileModel.updateOne({ _id }, update).exec()) .catch((err) => new Forbidden(err)); }, }; @@ -690,7 +690,7 @@ const renameService = { if (!obj) { return new NotFound('The given directory/file was not found!'); } - return FileModel.update({ _id }, { name: newName }).exec(); + return FileModel.updateOne({ _id }, { name: newName }).exec(); }) .catch((err) => new Forbidden(err)); }, @@ -872,7 +872,7 @@ const filePermissionService = { }), ]; - return FileModel.update( + return FileModel.updateOne( { _id }, { $set: { permissions }, diff --git a/src/services/lesson/hooks/index.js b/src/services/lesson/hooks/index.js index 36b5d422164..b45c4f5afff 100644 --- a/src/services/lesson/hooks/index.js +++ b/src/services/lesson/hooks/index.js @@ -128,7 +128,7 @@ const setPosition = async (context) => { const { courseId, courseGroupId } = context.data; if (courseId || courseGroupId) { const query = courseId ? { courseId } : { courseGroupId }; - context.data.position = await LessonModel.count(query).exec(); // next free position + context.data.position = await LessonModel.countDocuments(query).exec(); // next free position } return context; diff --git a/src/services/news/hooks/news.hooks.js b/src/services/news/hooks/news.hooks.js index c58ecaf2c2c..2a3ce1aacb0 100644 --- a/src/services/news/hooks/news.hooks.js +++ b/src/services/news/hooks/news.hooks.js @@ -2,7 +2,7 @@ const { newsHistoryModel } = require('../model'); const deleteNewsHistory = async (context) => { if (context.id) { - await newsHistoryModel.remove({ parentId: context.id }); + await newsHistoryModel.deleteOne({ parentId: context.id }); } return context; }; diff --git a/src/services/role/model.js b/src/services/role/model.js index 0e057042fcd..9a6d01477f5 100644 --- a/src/services/role/model.js +++ b/src/services/role/model.js @@ -33,7 +33,7 @@ const roleSchema = new Schema( // https://mongoosejs.com/docs/middleware.html const mongooseOperationsForClearCache = [ 'findOneAndDelete', - 'findOneAndRemove', + 'findOneAndDelete', 'findOneAndUpdate', 'deleteMany', 'deleteOne', diff --git a/src/services/role/utils/permissions.js b/src/services/role/utils/permissions.js index e39dfb2c863..90e52c350bf 100644 --- a/src/services/role/utils/permissions.js +++ b/src/services/role/utils/permissions.js @@ -22,7 +22,7 @@ const ROLES = { const definePermissions = (env, role, ...permissions) => { if (Configuration.get(env)) { // set defaul permission - Role.update( + Role.updateOne( { name: role, }, @@ -37,7 +37,7 @@ const definePermissions = (env, role, ...permissions) => { ).exec(); } else { // remove defaul permission - Role.update( + Role.updateOne( { name: role, }, diff --git a/src/services/sync/repo/user.repo.js b/src/services/sync/repo/user.repo.js index 6dd412fc576..aa74257e4af 100644 --- a/src/services/sync/repo/user.repo.js +++ b/src/services/sync/repo/user.repo.js @@ -95,7 +95,7 @@ const updateUser = async (userId, changedUser) => { }; const deleteUser = async (userId) => { - await userModel.remove({ _id: userId }).lean().exec(); + await userModel.deleteOne({ _id: userId }).lean().exec(); }; const findImportUsersBySchoolAndName = async (schoolId, firstName, lastName) => { diff --git a/src/services/user-group/hooks/courses.js b/src/services/user-group/hooks/courses.js index aa50cc52a78..fe1547d3efb 100644 --- a/src/services/user-group/hooks/courses.js +++ b/src/services/user-group/hooks/courses.js @@ -60,7 +60,7 @@ const addWholeClassToCourse = async (hook) => { const userIds = _.flattenDeep(groupUsers).map((groupUser) => groupUser.userId); const uniqueUserIds = _.uniqWith(userIds, (a, b) => a === b); - await CourseModel.update({ _id: course._id }, { $addToSet: { userIds: { $each: uniqueUserIds } } }).exec(); + await CourseModel.updateOne({ _id: course._id }, { $addToSet: { userIds: { $each: uniqueUserIds } } }).exec(); return undefined; }); @@ -78,7 +78,7 @@ const addWholeClassToCourse = async (hook) => { // flatten deep arrays and remove duplicates studentIds = _.uniqWith(_.flattenDeep(studentIds), (e1, e2) => JSON.stringify(e1) === JSON.stringify(e2)); - await CourseModel.update({ _id: course._id }, { $addToSet: { userIds: { $each: studentIds } } }).exec(); + await CourseModel.updateOne({ _id: course._id }, { $addToSet: { userIds: { $each: studentIds } } }).exec(); return hook; }); @@ -118,7 +118,7 @@ const deleteWholeClassFromCourse = (hook) => { const userIds = _.flattenDeep(groupUsers).map((groupUser) => groupUser.userId); const uniqueUserIds = _.uniqWith(userIds, (a, b) => a === b); - await CourseModel.update( + await CourseModel.updateOne( { _id: course._id }, { $pull: { userIds: { $in: uniqueUserIds } } }, { multi: true } @@ -142,7 +142,7 @@ const deleteWholeClassFromCourse = (hook) => { studentIds = _.uniqWith(_.flattenDeep(studentIds), (e1, e2) => JSON.stringify(e1) === JSON.stringify(e2)); // remove class students from course DB and from hook body to not patch them back - await CourseModel.update( + await CourseModel.updateOne( { _id: course._id }, { $pull: { userIds: { $in: studentIds } } }, { multi: true } diff --git a/src/services/user-group/services/courseScopeLists.js b/src/services/user-group/services/courseScopeLists.js index 0ace66c6dcf..bd1e069b9ff 100644 --- a/src/services/user-group/services/courseScopeLists.js +++ b/src/services/user-group/services/courseScopeLists.js @@ -37,7 +37,7 @@ module.exports = (app) => { if (params.query.count === 'true') { const courseCount = await courseModel - .count({ + .countDocuments({ $and: [userQuery, untilQuery], }) .exec(); diff --git a/src/services/user/registration.js b/src/services/user/registration.js index bc9bdf28c26..d60f2a40d76 100644 --- a/src/services/user/registration.js +++ b/src/services/user/registration.js @@ -231,8 +231,8 @@ const registerUser = function register(data, params, app) { user = newUser; }) ) - .then(() => { - return app + .then(() => + app .service('nest-account-uc') .saveAccount({ username: user.email, @@ -248,8 +248,8 @@ const registerUser = function register(data, params, app) { const msg = 'Fehler beim Erstellen des Accounts.'; logger.warning(msg, err); return Promise.reject(new Error(msg)); - }); - }) + }) + ) .then(() => { // store consent if (data.parent_email) { @@ -291,14 +291,14 @@ const registerUser = function register(data, params, app) { if (oldUser) { rollbackPromises.push(User.replaceOne({ _id: user._id }, oldUser).exec()); } else { - rollbackPromises.push(User.findOneAndRemove({ _id: user._id }).exec()); + rollbackPromises.push(User.findOneAndDelete({ _id: user._id }).exec()); } } if (account && account._id) { rollbackPromises.push(app.service('nest-account-service').delete(account.id)); } if (consent && consent._id) { - rollbackPromises.push(consentModel.consentModel.findOneAndRemove({ _id: consent._id }).exec()); + rollbackPromises.push(consentModel.consentModel.findOneAndDelete({ _id: consent._id }).exec()); } return Promise.all(rollbackPromises) .catch((err) => { diff --git a/src/services/wopi/utils/filePostActionHelper.js b/src/services/wopi/utils/filePostActionHelper.js index addadb3fb65..348b57a21f9 100644 --- a/src/services/wopi/utils/filePostActionHelper.js +++ b/src/services/wopi/utils/filePostActionHelper.js @@ -24,8 +24,8 @@ const deleteFile = (file, payload, account, app) => { * adoption: the lockId was checked in a hook before */ const lock = (file) => { - file.lockId = mongoose.Types.ObjectId(); - return FileModel.update({ _id: file._id }, file) + file.lockId = new mongoose.Types.ObjectId(); + return FileModel.updateOne({ _id: file._id }, file) .exec() .then(() => Promise.resolve({ lockId: file.lockId })); }; @@ -37,7 +37,7 @@ const getLock = (file) => .then(() => Promise.resolve({ lockId: file.lockId })); /** https://wopirest.readthedocs.io/en/latest/files/Unlock.html */ -const unlock = (file) => FileModel.update({ _id: file._id }, { $unset: { lockId: 1 } }).exec(); +const unlock = (file) => FileModel.updateOne({ _id: file._id }, { $unset: { lockId: 1 } }).exec(); /** https://wopirest.readthedocs.io/en/latest/files/RenameFile.html */ const renameFile = (file, payload, account, app) => {