From 21971956b7feb7c96f93ebac8f097b3bf119099d Mon Sep 17 00:00:00 2001 From: Eric Mc Sween <5454374+emcsween@users.noreply.github.com> Date: Tue, 21 Mar 2023 09:21:57 -0400 Subject: [PATCH] Merge pull request #12219 from overleaf/em-camel-case-web Camel case variables in web GitOrigin-RevId: 28e61b759b27f71265f33ab64f588374dba610e0 --- .../AuthenticationController.js | 2 +- .../BetaProgram/BetaProgramController.js | 5 +- .../app/src/Features/Chat/ChatApiHandler.js | 47 +++++---- .../app/src/Features/Chat/ChatController.js | 49 +++++----- .../CollaboratorsEmailHandler.js | 5 +- .../src/Features/Compile/ClsiCookieManager.js | 98 +++++++++---------- .../Features/Contacts/ContactController.js | 21 ++-- .../src/Features/Contacts/ContactManager.js | 17 ++-- .../Downloads/ProjectDownloadsController.js | 17 ++-- .../Downloads/ProjectZipStreamManager.js | 2 +- .../Editor/EditorRealTimeController.js | 13 ++- .../web/app/src/Features/Email/EmailSender.js | 2 +- .../src/Features/Exports/ExportsController.js | 74 +++++++------- .../src/Features/Exports/ExportsHandler.js | 97 +++++++++--------- .../src/Features/History/RestoreManager.js | 35 ++++--- .../InactiveData/InactiveProjectController.js | 5 +- .../InactiveData/InactiveProjectManager.js | 27 +++-- .../LinkedFiles/LinkedFilesController.js | 29 +++--- .../LinkedFiles/LinkedFilesHandler.js | 95 +++++++++--------- .../Features/LinkedFiles/ProjectFileAgent.js | 73 +++++++------- .../src/Features/Metadata/MetaController.js | 57 +++++------ .../app/src/Features/Metadata/MetaHandler.js | 13 ++- .../Features/Project/ProjectApiController.js | 5 +- .../ProjectCollabratecDetailsHandler.js | 83 ++++++++-------- .../src/Features/Project/ProjectDeleter.js | 4 +- .../Features/Project/ProjectRootDocManager.js | 57 ++++++----- .../Features/Project/ProjectUpdateHandler.js | 13 ++- .../Features/ServerAdmin/AdminController.js | 5 +- .../Features/Subscription/RecurlyWrapper.js | 21 ++-- .../Subscription/SubscriptionController.js | 16 +-- .../SubscriptionGroupController.js | 4 +- .../Subscription/SubscriptionHandler.js | 6 +- .../Features/Templates/TemplatesController.js | 5 +- .../Features/Templates/TemplatesManager.js | 21 ++-- .../ThirdPartyDataStore/TpdsUpdateHandler.js | 2 +- .../ThirdPartyDataStore/TpdsUpdateSender.js | 2 +- .../Uploads/ProjectUploadController.js | 23 +++-- .../src/Features/User/UserSessionsManager.js | 9 +- services/web/app/src/Features/V1/V1Handler.js | 9 +- .../app/src/infrastructure/ExpressLocals.js | 2 +- services/web/app/src/util/bib2json.js | 2 +- .../launchpad/app/src/LaunchpadController.js | 6 +- services/web/scripts/history/debug_history.js | 6 +- .../web/test/acceptance/src/ApiClsiTests.js | 9 +- .../acceptance/src/ProjectFeaturesTests.js | 22 ++--- .../test/acceptance/src/RestoringFilesTest.js | 9 +- .../acceptance/src/SecurityHeadersTests.js | 27 +++-- .../AuthenticationControllerTests.js | 2 +- .../test/unit/src/Chat/ChatControllerTests.js | 5 +- .../Downloads/ProjectZipStreamManagerTests.js | 43 ++++---- .../src/Exports/ExportsControllerTests.js | 37 ++++--- .../unit/src/Exports/ExportsHandlerTests.js | 73 +++++++------- .../NotificationsHandlerTests.js | 25 +++-- .../src/Project/ProjectHistoryHandlerTests.js | 23 +++-- .../src/Project/ProjectOptionsHandlerTests.js | 49 +++++----- .../src/Project/ProjectUpdateHandlerTests.js | 19 ++-- 56 files changed, 685 insertions(+), 742 deletions(-) diff --git a/services/web/app/src/Features/Authentication/AuthenticationController.js b/services/web/app/src/Features/Authentication/AuthenticationController.js index 7448c64549..333f797d22 100644 --- a/services/web/app/src/Features/Authentication/AuthenticationController.js +++ b/services/web/app/src/Features/Authentication/AuthenticationController.js @@ -624,7 +624,7 @@ function _loginAsyncHandlers(req, user, anonymousAnalyticsId, isNewUser) { Analytics.identifyUser(user._id, anonymousAnalyticsId, isNewUser) logger.debug( - { email: user.email, user_id: user._id.toString() }, + { email: user.email, userId: user._id.toString() }, 'successful log in' ) diff --git a/services/web/app/src/Features/BetaProgram/BetaProgramController.js b/services/web/app/src/Features/BetaProgram/BetaProgramController.js index 64d9dd7070..528d40062e 100644 --- a/services/web/app/src/Features/BetaProgram/BetaProgramController.js +++ b/services/web/app/src/Features/BetaProgram/BetaProgramController.js @@ -36,10 +36,7 @@ const BetaProgramController = { optInPage(req, res, next) { const userId = SessionManager.getLoggedInUserId(req.session) - logger.debug( - { user_id: userId }, - 'showing beta participation page for user' - ) + logger.debug({ userId }, 'showing beta participation page for user') UserGetter.getUser(userId, function (err, user) { if (err) { OError.tag(err, 'error fetching user', { diff --git a/services/web/app/src/Features/Chat/ChatApiHandler.js b/services/web/app/src/Features/Chat/ChatApiHandler.js index 6e1ee966ee..fbd12f8488 100644 --- a/services/web/app/src/Features/Chat/ChatApiHandler.js +++ b/services/web/app/src/Features/Chat/ChatApiHandler.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, */ @@ -17,13 +16,13 @@ const request = require('request') const settings = require('@overleaf/settings') const { promisify } = require('util') -function getThreads(project_id, callback) { +function getThreads(projectId, callback) { if (callback == null) { callback = function () {} } return ChatApiHandler._apiRequest( { - url: `${settings.apis.chat.internal_url}/project/${project_id}/threads`, + url: `${settings.apis.chat.internal_url}/project/${projectId}/threads`, method: 'GET', json: true, }, @@ -31,13 +30,13 @@ function getThreads(project_id, callback) { ) } -function destroyProject(project_id, callback) { +function destroyProject(projectId, callback) { if (callback == null) { callback = function () {} } return ChatApiHandler._apiRequest( { - url: `${settings.apis.chat.internal_url}/project/${project_id}`, + url: `${settings.apis.chat.internal_url}/project/${projectId}`, method: 'DELETE', }, callback @@ -66,18 +65,18 @@ module.exports = ChatApiHandler = { }) }, - sendGlobalMessage(project_id, user_id, content, callback) { + sendGlobalMessage(projectId, userId, content, callback) { return ChatApiHandler._apiRequest( { - url: `${settings.apis.chat.internal_url}/project/${project_id}/messages`, + url: `${settings.apis.chat.internal_url}/project/${projectId}/messages`, method: 'POST', - json: { user_id, content }, + json: { user_id: userId, content }, }, callback ) }, - getGlobalMessages(project_id, limit, before, callback) { + getGlobalMessages(projectId, limit, before, callback) { const qs = {} if (limit != null) { qs.limit = limit @@ -88,7 +87,7 @@ module.exports = ChatApiHandler = { return ChatApiHandler._apiRequest( { - url: `${settings.apis.chat.internal_url}/project/${project_id}/messages`, + url: `${settings.apis.chat.internal_url}/project/${projectId}/messages`, method: 'GET', qs, json: true, @@ -97,67 +96,67 @@ module.exports = ChatApiHandler = { ) }, - sendComment(project_id, thread_id, user_id, content, callback) { + sendComment(projectId, threadId, userId, content, callback) { if (callback == null) { callback = function () {} } return ChatApiHandler._apiRequest( { - url: `${settings.apis.chat.internal_url}/project/${project_id}/thread/${thread_id}/messages`, + url: `${settings.apis.chat.internal_url}/project/${projectId}/thread/${threadId}/messages`, method: 'POST', - json: { user_id, content }, + json: { user_id: userId, content }, }, callback ) }, - resolveThread(project_id, thread_id, user_id, callback) { + resolveThread(projectId, threadId, userId, callback) { if (callback == null) { callback = function () {} } return ChatApiHandler._apiRequest( { - url: `${settings.apis.chat.internal_url}/project/${project_id}/thread/${thread_id}/resolve`, + url: `${settings.apis.chat.internal_url}/project/${projectId}/thread/${threadId}/resolve`, method: 'POST', - json: { user_id }, + json: { user_id: userId }, }, callback ) }, - reopenThread(project_id, thread_id, callback) { + reopenThread(projectId, threadId, callback) { if (callback == null) { callback = function () {} } return ChatApiHandler._apiRequest( { - url: `${settings.apis.chat.internal_url}/project/${project_id}/thread/${thread_id}/reopen`, + url: `${settings.apis.chat.internal_url}/project/${projectId}/thread/${threadId}/reopen`, method: 'POST', }, callback ) }, - deleteThread(project_id, thread_id, callback) { + deleteThread(projectId, threadId, callback) { if (callback == null) { callback = function () {} } return ChatApiHandler._apiRequest( { - url: `${settings.apis.chat.internal_url}/project/${project_id}/thread/${thread_id}`, + url: `${settings.apis.chat.internal_url}/project/${projectId}/thread/${threadId}`, method: 'DELETE', }, callback ) }, - editMessage(project_id, thread_id, message_id, userId, content, callback) { + editMessage(projectId, threadId, messageId, userId, content, callback) { if (callback == null) { callback = function () {} } return ChatApiHandler._apiRequest( { - url: `${settings.apis.chat.internal_url}/project/${project_id}/thread/${thread_id}/messages/${message_id}/edit`, + url: `${settings.apis.chat.internal_url}/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`, method: 'POST', json: { content, @@ -168,13 +167,13 @@ module.exports = ChatApiHandler = { ) }, - deleteMessage(project_id, thread_id, message_id, callback) { + deleteMessage(projectId, threadId, messageId, callback) { if (callback == null) { callback = function () {} } return ChatApiHandler._apiRequest( { - url: `${settings.apis.chat.internal_url}/project/${project_id}/thread/${thread_id}/messages/${message_id}`, + url: `${settings.apis.chat.internal_url}/project/${projectId}/thread/${threadId}/messages/${messageId}`, method: 'DELETE', }, callback diff --git a/services/web/app/src/Features/Chat/ChatController.js b/services/web/app/src/Features/Chat/ChatController.js index 7a5b4b21b9..6050d8e22c 100644 --- a/services/web/app/src/Features/Chat/ChatController.js +++ b/services/web/app/src/Features/Chat/ChatController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-unused-vars, @@ -23,16 +22,16 @@ const async = require('async') module.exports = ChatController = { sendMessage(req, res, next) { - const { project_id } = req.params - const { content, client_id } = req.body - const user_id = SessionManager.getLoggedInUserId(req.session) - if (user_id == null) { + const { project_id: projectId } = req.params + const { content, client_id: clientId } = req.body + const userId = SessionManager.getLoggedInUserId(req.session) + if (userId == null) { const err = new Error('no logged-in user') return next(err) } return ChatApiHandler.sendGlobalMessage( - project_id, - user_id, + projectId, + userId, content, function (err, message) { if (err != null) { @@ -45,9 +44,9 @@ module.exports = ChatController = { return next(err) } message.user = UserInfoController.formatPersonalInfo(user) - message.clientId = client_id + message.clientId = clientId EditorRealTimeController.emitToRoom( - project_id, + projectId, 'new-chat-message', message ) @@ -59,10 +58,10 @@ module.exports = ChatController = { }, getMessages(req, res, next) { - const { project_id } = req.params + const { project_id: projectId } = req.params const { query } = req return ChatApiHandler.getGlobalMessages( - project_id, + projectId, query.limit, query.before, function (err, messages) { @@ -86,42 +85,42 @@ module.exports = ChatController = { // There will be a lot of repitition of user_ids, so first build a list // of unique ones to perform db look ups on, then use these to populate the // user fields - let message, thread, thread_id, user_id + let message, thread, threadId, userId if (callback == null) { callback = function () {} } - const user_ids = {} - for (thread_id in threads) { - thread = threads[thread_id] + const userIds = {} + for (threadId in threads) { + thread = threads[threadId] if (thread.resolved) { - user_ids[thread.resolved_by_user_id] = true + userIds[thread.resolved_by_user_id] = true } for (message of Array.from(thread.messages)) { - user_ids[message.user_id] = true + userIds[message.user_id] = true } } const jobs = [] const users = {} - for (user_id in user_ids) { - const _ = user_ids[user_id] - ;(user_id => + for (userId in userIds) { + const _ = userIds[userId] + ;(userId => jobs.push(cb => - UserInfoManager.getPersonalInfo(user_id, function (error, user) { + UserInfoManager.getPersonalInfo(userId, function (error, user) { if (error != null) return cb(error) user = UserInfoController.formatPersonalInfo(user) - users[user_id] = user + users[userId] = user cb() }) - ))(user_id) + ))(userId) } return async.series(jobs, function (error) { if (error != null) { return callback(error) } - for (thread_id in threads) { - thread = threads[thread_id] + for (threadId in threads) { + thread = threads[threadId] if (thread.resolved) { thread.resolved_by_user = users[thread.resolved_by_user_id] } diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsEmailHandler.js b/services/web/app/src/Features/Collaborators/CollaboratorsEmailHandler.js index cd744e368a..6831f46c58 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsEmailHandler.js +++ b/services/web/app/src/Features/Collaborators/CollaboratorsEmailHandler.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, */ @@ -19,8 +18,8 @@ module.exports = CollaboratorsEmailHandler = { ) }, - notifyUserOfProjectInvite(project_id, email, invite, sendingUser, callback) { - Project.findOne({ _id: project_id }) + notifyUserOfProjectInvite(projectId, email, invite, sendingUser, callback) { + Project.findOne({ _id: projectId }) .select('name owner_ref') .populate('owner_ref') .exec(function (err, project) { diff --git a/services/web/app/src/Features/Compile/ClsiCookieManager.js b/services/web/app/src/Features/Compile/ClsiCookieManager.js index f7909ad1e5..a5f0bc3fd8 100644 --- a/services/web/app/src/Features/Compile/ClsiCookieManager.js +++ b/services/web/app/src/Features/Compile/ClsiCookieManager.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, */ @@ -11,7 +10,7 @@ * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -let rclient_secondary +let rclientSecondary const { URL, URLSearchParams } = require('url') const OError = require('@overleaf/o-error') const Settings = require('@overleaf/settings') @@ -19,7 +18,7 @@ const request = require('request').defaults({ timeout: 30 * 1000 }) const RedisWrapper = require('../../infrastructure/RedisWrapper') const rclient = RedisWrapper.client('clsi_cookie') if (Settings.redis.clsi_cookie_secondary != null) { - rclient_secondary = RedisWrapper.client('clsi_cookie_secondary') + rclientSecondary = RedisWrapper.client('clsi_cookie_secondary') } const Cookie = require('cookie') const logger = require('@overleaf/logger') @@ -31,17 +30,17 @@ const clsiCookiesEnabled = module.exports = function (backendGroup) { return { - buildKey(project_id, user_id) { + buildKey(projectId, userId) { if (backendGroup != null) { - return `clsiserver:${backendGroup}:${project_id}:${user_id}` + return `clsiserver:${backendGroup}:${projectId}:${userId}` } else { - return `clsiserver:${project_id}:${user_id}` + return `clsiserver:${projectId}:${userId}` } }, _getServerId( - project_id, - user_id, + projectId, + userId, compileGroup, compileBackendClass, callback @@ -49,30 +48,27 @@ module.exports = function (backendGroup) { if (callback == null) { callback = function () {} } - return rclient.get( - this.buildKey(project_id, user_id), - (err, serverId) => { - if (err != null) { - return callback(err) - } - if (serverId == null || serverId === '') { - return this._populateServerIdViaRequest( - project_id, - user_id, - compileGroup, - compileBackendClass, - callback - ) - } else { - return callback(null, serverId) - } + return rclient.get(this.buildKey(projectId, userId), (err, serverId) => { + if (err != null) { + return callback(err) } - ) + if (serverId == null || serverId === '') { + return this._populateServerIdViaRequest( + projectId, + userId, + compileGroup, + compileBackendClass, + callback + ) + } else { + return callback(null, serverId) + } + }) }, _populateServerIdViaRequest( - project_id, - user_id, + projectId, + userId, compileGroup, compileBackendClass, callback @@ -80,9 +76,7 @@ module.exports = function (backendGroup) { if (callback == null) { callback = function () {} } - const u = new URL( - `${Settings.apis.clsi.url}/project/${project_id}/status` - ) + const u = new URL(`${Settings.apis.clsi.url}/project/${projectId}/status`) u.search = new URLSearchParams({ compileGroup, compileBackendClass, @@ -90,13 +84,13 @@ module.exports = function (backendGroup) { request.post(u.href, (err, res, body) => { if (err != null) { OError.tag(err, 'error getting initial server id for project', { - project_id, + project_id: projectId, }) return callback(err) } this.setServerId( - project_id, - user_id, + projectId, + userId, compileGroup, compileBackendClass, res, @@ -104,7 +98,7 @@ module.exports = function (backendGroup) { function (err, serverId) { if (err != null) { logger.warn( - { err, project_id }, + { err, projectId }, 'error setting server id via populate request' ) } @@ -153,8 +147,8 @@ module.exports = function (backendGroup) { }, setServerId( - project_id, - user_id, + projectId, + userId, compileGroup, compileBackendClass, response, @@ -171,7 +165,7 @@ module.exports = function (backendGroup) { if (serverId == null) { // We don't get a cookie back if it hasn't changed return rclient.expire( - this.buildKey(project_id, user_id), + this.buildKey(projectId, userId), this._getTTLInSeconds(previous), err => callback(err, undefined) ) @@ -186,45 +180,45 @@ module.exports = function (backendGroup) { compileBackendClass ) } - if (rclient_secondary != null) { + if (rclientSecondary != null) { this._setServerIdInRedis( - rclient_secondary, - project_id, - user_id, + rclientSecondary, + projectId, + userId, serverId, () => {} ) } - this._setServerIdInRedis(rclient, project_id, user_id, serverId, err => + this._setServerIdInRedis(rclient, projectId, userId, serverId, err => callback(err, serverId) ) }, - _setServerIdInRedis(rclient, project_id, user_id, serverId, callback) { + _setServerIdInRedis(rclient, projectId, userId, serverId, callback) { if (callback == null) { callback = function () {} } rclient.setex( - this.buildKey(project_id, user_id), + this.buildKey(projectId, userId), this._getTTLInSeconds(serverId), serverId, callback ) }, - clearServerId(project_id, user_id, callback) { + clearServerId(projectId, userId, callback) { if (callback == null) { callback = function () {} } if (!clsiCookiesEnabled) { return callback() } - return rclient.del(this.buildKey(project_id, user_id), callback) + return rclient.del(this.buildKey(projectId, userId), callback) }, getCookieJar( - project_id, - user_id, + projectId, + userId, compileGroup, compileBackendClass, callback @@ -236,14 +230,14 @@ module.exports = function (backendGroup) { return callback(null, request.jar(), undefined) } return this._getServerId( - project_id, - user_id, + projectId, + userId, compileGroup, compileBackendClass, (err, serverId) => { if (err != null) { OError.tag(err, 'error getting server id', { - project_id, + project_id: projectId, }) return callback(err) } diff --git a/services/web/app/src/Features/Contacts/ContactController.js b/services/web/app/src/Features/Contacts/ContactController.js index 0544f38e59..ee5b6eda2c 100644 --- a/services/web/app/src/Features/Contacts/ContactController.js +++ b/services/web/app/src/Features/Contacts/ContactController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, */ @@ -21,16 +20,16 @@ const Modules = require('../../infrastructure/Modules') module.exports = ContactsController = { getContacts(req, res, next) { - const user_id = SessionManager.getLoggedInUserId(req.session) + const userId = SessionManager.getLoggedInUserId(req.session) return ContactManager.getContactIds( - user_id, + userId, { limit: 50 }, - function (error, contact_ids) { + function (error, contactIds) { if (error != null) { return next(error) } return UserGetter.getUsers( - contact_ids, + contactIds, { email: 1, first_name: 1, @@ -44,9 +43,9 @@ module.exports = ContactsController = { // UserGetter.getUsers may not preserve order so put them back in order const positions = {} - for (let i = 0; i < contact_ids.length; i++) { - const contact_id = contact_ids[i] - positions[contact_id] = i + for (let i = 0; i < contactIds.length; i++) { + const contactId = contactIds[i] + positions[contactId] = i } contacts.sort( (a, b) => @@ -61,14 +60,14 @@ module.exports = ContactsController = { return Modules.hooks.fire( 'getContacts', - user_id, + userId, contacts, - function (error, additional_contacts) { + function (error, additionalContacts) { if (error != null) { return next(error) } contacts = contacts.concat( - ...Array.from(additional_contacts || []) + ...Array.from(additionalContacts || []) ) return res.json({ contacts, diff --git a/services/web/app/src/Features/Contacts/ContactManager.js b/services/web/app/src/Features/Contacts/ContactManager.js index 31cddf494d..ae0f872fe4 100644 --- a/services/web/app/src/Features/Contacts/ContactManager.js +++ b/services/web/app/src/Features/Contacts/ContactManager.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-unused-vars, @@ -18,14 +17,14 @@ const request = require('request') const settings = require('@overleaf/settings') module.exports = ContactManager = { - getContactIds(user_id, options, callback) { + getContactIds(userId, options, callback) { if (options == null) { options = { limits: 50 } } if (callback == null) { callback = function () {} } - const url = `${settings.apis.contacts.url}/user/${user_id}/contacts` + const url = `${settings.apis.contacts.url}/user/${userId}/contacts` return request.get( { url, @@ -45,7 +44,7 @@ module.exports = ContactManager = { } else { error = new OError( `contacts api responded with non-success code: ${res.statusCode}`, - { user_id } + { user_id: userId } ) return callback(error) } @@ -53,16 +52,16 @@ module.exports = ContactManager = { ) }, - addContact(user_id, contact_id, callback) { + addContact(userId, contactId, callback) { if (callback == null) { callback = function () {} } - const url = `${settings.apis.contacts.url}/user/${user_id}/contacts` + const url = `${settings.apis.contacts.url}/user/${userId}/contacts` return request.post( { url, json: { - contact_id, + contact_id: contactId, }, jar: false, }, @@ -79,8 +78,8 @@ module.exports = ContactManager = { error = new OError( `contacts api responded with non-success code: ${res.statusCode}`, { - user_id, - contact_id, + user_id: userId, + contact_id: contactId, } ) return callback(error) diff --git a/services/web/app/src/Features/Downloads/ProjectDownloadsController.js b/services/web/app/src/Features/Downloads/ProjectDownloadsController.js index 387643bdc9..7e52c4638d 100644 --- a/services/web/app/src/Features/Downloads/ProjectDownloadsController.js +++ b/services/web/app/src/Features/Downloads/ProjectDownloadsController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, */ @@ -21,23 +20,23 @@ const { prepareZipAttachment } = require('../../infrastructure/Response') module.exports = ProjectDownloadsController = { downloadProject(req, res, next) { - const project_id = req.params.Project_id + const projectId = req.params.Project_id Metrics.inc('zip-downloads') return DocumentUpdaterHandler.flushProjectToMongo( - project_id, + projectId, function (error) { if (error != null) { return next(error) } return ProjectGetter.getProject( - project_id, + projectId, { name: true }, function (error, project) { if (error != null) { return next(error) } return ProjectZipStreamManager.createZipStreamForProject( - project_id, + projectId, function (error, stream) { if (error != null) { return next(error) @@ -53,23 +52,23 @@ module.exports = ProjectDownloadsController = { }, downloadMultipleProjects(req, res, next) { - const project_ids = req.query.project_ids.split(',') + const projectIds = req.query.project_ids.split(',') Metrics.inc('zip-downloads-multiple') return DocumentUpdaterHandler.flushMultipleProjectsToMongo( - project_ids, + projectIds, function (error) { if (error != null) { return next(error) } return ProjectZipStreamManager.createZipStreamForMultipleProjects( - project_ids, + projectIds, function (error, stream) { if (error != null) { return next(error) } prepareZipAttachment( res, - `Overleaf Projects (${project_ids.length} items).zip` + `Overleaf Projects (${projectIds.length} items).zip` ) return stream.pipe(res) } diff --git a/services/web/app/src/Features/Downloads/ProjectZipStreamManager.js b/services/web/app/src/Features/Downloads/ProjectZipStreamManager.js index a5e57a4f9c..11f292b572 100644 --- a/services/web/app/src/Features/Downloads/ProjectZipStreamManager.js +++ b/services/web/app/src/Features/Downloads/ProjectZipStreamManager.js @@ -121,7 +121,7 @@ module.exports = ProjectZipStreamManager = { (error, stream) => { if (error) { logger.warn( - { err: error, projectId, file_id: file._id }, + { err: error, projectId, fileId: file._id }, 'something went wrong adding file to zip archive' ) return cb(error) diff --git a/services/web/app/src/Features/Editor/EditorRealTimeController.js b/services/web/app/src/Features/Editor/EditorRealTimeController.js index 726fb582f3..086870e8f1 100644 --- a/services/web/app/src/Features/Editor/EditorRealTimeController.js +++ b/services/web/app/src/Features/Editor/EditorRealTimeController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, */ @@ -24,20 +23,20 @@ const RND = crypto.randomBytes(4).toString('hex') // generate a random key for t let COUNT = 0 module.exports = EditorRealTimeController = { - emitToRoom(room_id, message, ...payload) { + emitToRoom(roomId, message, ...payload) { // create a unique message id using a counter - const message_id = `web:${HOST}:${RND}-${COUNT++}` + const messageId = `web:${HOST}:${RND}-${COUNT++}` let channel - if (room_id === 'all' || !Settings.publishOnIndividualChannels) { + if (roomId === 'all' || !Settings.publishOnIndividualChannels) { channel = 'editor-events' } else { - channel = `editor-events:${room_id}` + channel = `editor-events:${roomId}` } const blob = JSON.stringify({ - room_id, + room_id: roomId, message, payload, - _id: message_id, + _id: messageId, }) Metrics.summary('redis.publish.editor-events', blob.length, { status: message, diff --git a/services/web/app/src/Features/Email/EmailSender.js b/services/web/app/src/Features/Email/EmailSender.js index 41cee94c25..008d277c97 100644 --- a/services/web/app/src/Features/Email/EmailSender.js +++ b/services/web/app/src/Features/Email/EmailSender.js @@ -78,7 +78,7 @@ async function sendEmail(options) { if (!canContinue) { logger.debug( { - sendingUser_id: options.sendingUser_id, + sendingUserId: options.sendingUser_id, to: options.to, subject: options.subject, canContinue, diff --git a/services/web/app/src/Features/Exports/ExportsController.js b/services/web/app/src/Features/Exports/ExportsController.js index 51899f620c..181de74882 100644 --- a/services/web/app/src/Features/Exports/ExportsController.js +++ b/services/web/app/src/Features/Exports/ExportsController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, */ // TODO: This file was created by bulk-decaffeinate. @@ -16,42 +15,43 @@ const logger = require('@overleaf/logger') module.exports = { exportProject(req, res, next) { - const { project_id, brand_variation_id } = req.params - const user_id = SessionManager.getLoggedInUserId(req.session) - const export_params = { - project_id, - brand_variation_id, - user_id, + const { project_id: projectId, brand_variation_id: brandVariationId } = + req.params + const userId = SessionManager.getLoggedInUserId(req.session) + const exportParams = { + project_id: projectId, + brand_variation_id: brandVariationId, + user_id: userId, } if (req.body) { if (req.body.firstName) { - export_params.first_name = req.body.firstName.trim() + exportParams.first_name = req.body.firstName.trim() } if (req.body.lastName) { - export_params.last_name = req.body.lastName.trim() + exportParams.last_name = req.body.lastName.trim() } // additional parameters for gallery exports if (req.body.title) { - export_params.title = req.body.title.trim() + exportParams.title = req.body.title.trim() } if (req.body.description) { - export_params.description = req.body.description.trim() + exportParams.description = req.body.description.trim() } if (req.body.author) { - export_params.author = req.body.author.trim() + exportParams.author = req.body.author.trim() } if (req.body.license) { - export_params.license = req.body.license.trim() + exportParams.license = req.body.license.trim() } if (req.body.showSource != null) { - export_params.show_source = req.body.showSource + exportParams.show_source = req.body.showSource } } return ExportsHandler.exportProject( - export_params, - function (err, export_data) { + exportParams, + function (err, exportData) { if (err != null) { if (err.forwardResponse != null) { logger.debug( @@ -66,24 +66,24 @@ module.exports = { } logger.debug( { - user_id, - project_id, - brand_variation_id, - export_v1_id: export_data.v1_id, + userId, + projectId, + brandVariationId, + exportV1Id: exportData.v1_id, }, 'exported project' ) return res.json({ - export_v1_id: export_data.v1_id, - message: export_data.message, + export_v1_id: exportData.v1_id, + message: exportData.message, }) } ) }, exportStatus(req, res) { - const { export_id } = req.params - return ExportsHandler.fetchExport(export_id, function (err, export_json) { + const { export_id: exportId } = req.params + return ExportsHandler.fetchExport(exportId, function (err, exportJson) { let json if (err != null) { json = { @@ -93,34 +93,34 @@ module.exports = { res.json({ export_json: json }) return err } - const parsed_export = JSON.parse(export_json) + const parsedExport = JSON.parse(exportJson) json = { - status_summary: parsed_export.status_summary, - status_detail: parsed_export.status_detail, - partner_submission_id: parsed_export.partner_submission_id, - v2_user_email: parsed_export.v2_user_email, - v2_user_first_name: parsed_export.v2_user_first_name, - v2_user_last_name: parsed_export.v2_user_last_name, - title: parsed_export.title, - token: parsed_export.token, + status_summary: parsedExport.status_summary, + status_detail: parsedExport.status_detail, + partner_submission_id: parsedExport.partner_submission_id, + v2_user_email: parsedExport.v2_user_email, + v2_user_first_name: parsedExport.v2_user_first_name, + v2_user_last_name: parsedExport.v2_user_last_name, + title: parsedExport.title, + token: parsedExport.token, } return res.json({ export_json: json }) }) }, exportDownload(req, res, next) { - const { type, export_id } = req.params + const { type, export_id: exportId } = req.params SessionManager.getLoggedInUserId(req.session) return ExportsHandler.fetchDownload( - export_id, + exportId, type, - function (err, export_file_url) { + function (err, exportFileUrl) { if (err != null) { return next(err) } - return res.redirect(export_file_url) + return res.redirect(exportFileUrl) } ) }, diff --git a/services/web/app/src/Features/Exports/ExportsHandler.js b/services/web/app/src/Features/Exports/ExportsHandler.js index 4e7ac859a6..9854cd3711 100644 --- a/services/web/app/src/Features/Exports/ExportsHandler.js +++ b/services/web/app/src/Features/Exports/ExportsHandler.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-unused-vars, @@ -27,59 +26,59 @@ request = request.defaults() settings = require('@overleaf/settings') module.exports = ExportsHandler = { - exportProject(export_params, callback) { + exportProject(exportParams, callback) { if (callback == null) { callback = function () {} } return ExportsHandler._buildExport( - export_params, - function (err, export_data) { + exportParams, + function (err, exportData) { if (err != null) { return callback(err) } - return ExportsHandler._requestExport(export_data, function (err, body) { + return ExportsHandler._requestExport(exportData, function (err, body) { if (err != null) { return callback(err) } - export_data.v1_id = body.exportId - export_data.message = body.message + exportData.v1_id = body.exportId + exportData.message = body.message // TODO: possibly store the export data in Mongo - return callback(null, export_data) + return callback(null, exportData) }) } ) }, - _buildExport(export_params, callback) { + _buildExport(exportParams, callback) { if (callback == null) { callback = function () {} } const { - project_id, - user_id, - brand_variation_id, + project_id: projectId, + user_id: userId, + brand_variation_id: brandVariationId, title, description, author, license, - show_source, - } = export_params + show_source: showSource, + } = exportParams const jobs = { project(cb) { - return ProjectGetter.getProject(project_id, cb) + return ProjectGetter.getProject(projectId, cb) }, // TODO: when we update async, signature will change from (cb, results) to (results, cb) rootDoc: [ 'project', (results, cb) => ProjectRootDocManager.ensureRootDocumentIsValid( - project_id, + projectId, function (error) { if (error != null) { return callback(error) } return ProjectLocator.findRootDoc( - { project: results.project, project_id }, + { project: results.project, project_id: projectId }, cb ) } @@ -87,19 +86,19 @@ module.exports = ExportsHandler = { ], user(cb) { return UserGetter.getUser( - user_id, + userId, { first_name: 1, last_name: 1, email: 1, overleaf: 1 }, cb ) }, historyVersion(cb) { return ProjectHistoryHandler.ensureHistoryExistsForProject( - project_id, + projectId, function (error) { if (error != null) { return callback(error) } - return ExportsHandler._requestVersion(project_id, cb) + return ExportsHandler._requestVersion(projectId, cb) } ) }, @@ -108,9 +107,9 @@ module.exports = ExportsHandler = { return async.auto(jobs, function (err, results) { if (err != null) { OError.tag(err, 'error building project export', { - project_id, - user_id, - brand_variation_id, + project_id: projectId, + user_id: userId, + brand_variation_id: brandVariationId, }) return callback(err) } @@ -118,19 +117,19 @@ module.exports = ExportsHandler = { const { project, rootDoc, user, historyVersion } = results if (!rootDoc || rootDoc[1] == null) { err = new OError('cannot export project without root doc', { - project_id, + project_id: projectId, }) return callback(err) } - if (export_params.first_name && export_params.last_name) { - user.first_name = export_params.first_name - user.last_name = export_params.last_name + if (exportParams.first_name && exportParams.last_name) { + user.first_name = exportParams.first_name + user.last_name = exportParams.last_name } - const export_data = { + const exportData = { project: { - id: project_id, + id: projectId, rootDocPath: rootDoc[1] != null ? rootDoc[1].fileSystem : undefined, historyId: project.overleaf?.history?.id, historyVersion, @@ -143,11 +142,11 @@ module.exports = ExportsHandler = { description, author, license, - showSource: show_source, + showSource, }, }, user: { - id: user_id, + id: userId, firstName: user.first_name, lastName: user.last_name, email: user.email, @@ -155,17 +154,17 @@ module.exports = ExportsHandler = { v1UserId: user.overleaf != null ? user.overleaf.id : undefined, }, destination: { - brandVariationId: brand_variation_id, + brandVariationId, }, options: { callbackUrl: null, }, // for now, until we want v1 to call us back } - return callback(null, export_data) + return callback(null, exportData) }) }, - _requestExport(export_data, callback) { + _requestExport(exportData, callback) { if (callback == null) { callback = function () {} } @@ -173,20 +172,20 @@ module.exports = ExportsHandler = { { url: `${settings.apis.v1.url}/api/v1/sharelatex/exports`, auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass }, - json: export_data, + json: exportData, timeout: settings.apis.v1.timeout, }, function (err, res, body) { if (err != null) { OError.tag(err, 'error making request to v1 export', { - export: export_data, + export: exportData, }) return callback(err) } else if (res.statusCode >= 200 && res.statusCode < 300) { return callback(null, body) } else { logger.warn( - { export: export_data }, + { export: exportData }, `v1 export returned failure; forwarding: ${body}` ) // pass the v1 error along for the publish modal to handle @@ -197,19 +196,19 @@ module.exports = ExportsHandler = { ) }, - _requestVersion(project_id, callback) { + _requestVersion(projectId, callback) { if (callback == null) { callback = function () {} } return request.get( { - url: `${settings.apis.project_history.url}/project/${project_id}/version`, + url: `${settings.apis.project_history.url}/project/${projectId}/version`, json: true, }, function (err, res, body) { if (err != null) { OError.tag(err, 'error making request to project history', { - project_id, + project_id: projectId, }) return callback(err) } else if (res.statusCode >= 200 && res.statusCode < 300) { @@ -217,7 +216,7 @@ module.exports = ExportsHandler = { } else { err = new OError( `project history version returned a failure status code: ${res.statusCode}`, - { project_id } + { project_id: projectId } ) return callback(err) } @@ -225,20 +224,20 @@ module.exports = ExportsHandler = { ) }, - fetchExport(export_id, callback) { + fetchExport(exportId, callback) { if (callback == null) { callback = function () {} } return request.get( { - url: `${settings.apis.v1.url}/api/v1/sharelatex/exports/${export_id}`, + url: `${settings.apis.v1.url}/api/v1/sharelatex/exports/${exportId}`, auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass }, timeout: settings.apis.v1.timeout, }, function (err, res, body) { if (err != null) { OError.tag(err, 'error making request to v1 export', { - export: export_id, + export: exportId, }) return callback(err) } else if (res.statusCode >= 200 && res.statusCode < 300) { @@ -246,7 +245,7 @@ module.exports = ExportsHandler = { } else { err = new OError( `v1 export returned a failure status code: ${res.statusCode}`, - { export: export_id } + { export: exportId } ) return callback(err) } @@ -254,20 +253,20 @@ module.exports = ExportsHandler = { ) }, - fetchDownload(export_id, type, callback) { + fetchDownload(exportId, type, callback) { if (callback == null) { callback = function () {} } return request.get( { - url: `${settings.apis.v1.url}/api/v1/sharelatex/exports/${export_id}/${type}_url`, + url: `${settings.apis.v1.url}/api/v1/sharelatex/exports/${exportId}/${type}_url`, auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass }, timeout: settings.apis.v1.timeout, }, function (err, res, body) { if (err != null) { OError.tag(err, 'error making request to v1 export', { - export: export_id, + export: exportId, }) return callback(err) } else if (res.statusCode >= 200 && res.statusCode < 300) { @@ -275,7 +274,7 @@ module.exports = ExportsHandler = { } else { err = new OError( `v1 export returned a failure status code: ${res.statusCode}`, - { export: export_id } + { export: exportId } ) return callback(err) } diff --git a/services/web/app/src/Features/History/RestoreManager.js b/services/web/app/src/Features/History/RestoreManager.js index d0c7b5a11f..27ac54f7b3 100644 --- a/services/web/app/src/Features/History/RestoreManager.js +++ b/services/web/app/src/Features/History/RestoreManager.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-unused-vars, @@ -23,7 +22,7 @@ const Errors = require('../Errors/Errors') const moment = require('moment') module.exports = RestoreManager = { - restoreDocFromDeletedDoc(user_id, project_id, doc_id, name, callback) { + restoreDocFromDeletedDoc(userId, projectId, docId, name, callback) { // This is the legacy method for restoring a doc from the SL track-changes/deletedDocs system. // It looks up the deleted doc's contents, and then creates a new doc with the same content. // We don't actually remove the deleted doc entry, just create a new one from its lines. @@ -31,8 +30,8 @@ module.exports = RestoreManager = { callback = function () {} } return ProjectEntityHandler.getDoc( - project_id, - doc_id, + projectId, + docId, { include_deleted: true }, function (error, lines) { if (error != null) { @@ -40,12 +39,12 @@ module.exports = RestoreManager = { } const addDocWithName = (name, callback) => EditorController.addDoc( - project_id, + projectId, null, name, lines, 'restore', - user_id, + userId, callback ) return RestoreManager._addEntityWithUniqueName( @@ -57,12 +56,12 @@ module.exports = RestoreManager = { ) }, - restoreFileFromV2(user_id, project_id, version, pathname, callback) { + restoreFileFromV2(userId, projectId, version, pathname, callback) { if (callback == null) { callback = function () {} } return RestoreManager._writeFileVersionToDisk( - project_id, + projectId, version, pathname, function (error, fsPath) { @@ -76,17 +75,17 @@ module.exports = RestoreManager = { dirname = '' } return RestoreManager._findOrCreateFolder( - project_id, + projectId, dirname, - function (error, parent_folder_id) { + function (error, parentFolderId) { if (error != null) { return callback(error) } const addEntityWithName = (name, callback) => FileSystemImportManager.addEntity( - user_id, - project_id, - parent_folder_id, + userId, + projectId, + parentFolderId, name, fsPath, false, @@ -103,12 +102,12 @@ module.exports = RestoreManager = { ) }, - _findOrCreateFolder(project_id, dirname, callback) { + _findOrCreateFolder(projectId, dirname, callback) { if (callback == null) { callback = function () {} } return EditorController.mkdirp( - project_id, + projectId, dirname, function (error, newFolders, lastFolder) { if (error != null) { @@ -145,13 +144,13 @@ module.exports = RestoreManager = { }) }, - _writeFileVersionToDisk(project_id, version, pathname, callback) { + _writeFileVersionToDisk(projectId, version, pathname, callback) { if (callback == null) { callback = function () {} } const url = `${ Settings.apis.project_history.url - }/project/${project_id}/version/${version}/${encodeURIComponent(pathname)}` - return FileWriter.writeUrlToDisk(project_id, url, callback) + }/project/${projectId}/version/${version}/${encodeURIComponent(pathname)}` + return FileWriter.writeUrlToDisk(projectId, url, callback) }, } diff --git a/services/web/app/src/Features/InactiveData/InactiveProjectController.js b/services/web/app/src/Features/InactiveData/InactiveProjectController.js index d48e30992e..62bc12b773 100644 --- a/services/web/app/src/Features/InactiveData/InactiveProjectController.js +++ b/services/web/app/src/Features/InactiveData/InactiveProjectController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, */ // TODO: This file was created by bulk-decaffeinate. @@ -33,8 +32,8 @@ module.exports = { }, deactivateProject(req, res) { - const { project_id } = req.params - return InactiveProjectManager.deactivateProject(project_id, function (err) { + const { project_id: projectId } = req.params + return InactiveProjectManager.deactivateProject(projectId, function (err) { if (err != null) { return res.sendStatus(500) } else { diff --git a/services/web/app/src/Features/InactiveData/InactiveProjectManager.js b/services/web/app/src/Features/InactiveData/InactiveProjectManager.js index 0ab734e140..e460f931dd 100644 --- a/services/web/app/src/Features/InactiveData/InactiveProjectManager.js +++ b/services/web/app/src/Features/InactiveData/InactiveProjectManager.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, */ // TODO: This file was created by bulk-decaffeinate. @@ -22,19 +21,19 @@ const { ObjectId } = require('mongodb') const MILISECONDS_IN_DAY = 86400000 module.exports = InactiveProjectManager = { - reactivateProjectIfRequired(project_id, callback) { + reactivateProjectIfRequired(projectId, callback) { ProjectGetter.getProject( - project_id, + projectId, { active: true }, function (err, project) { if (err != null) { OError.tag(err, 'error getting project', { - project_id, + project_id: projectId, }) return callback(err) } logger.debug( - { project_id, active: project.active }, + { projectId, active: project.active }, 'seeing if need to reactivate project' ) @@ -42,14 +41,14 @@ module.exports = InactiveProjectManager = { return callback() } - DocstoreManager.unarchiveProject(project_id, function (err) { + DocstoreManager.unarchiveProject(projectId, function (err) { if (err != null) { OError.tag(err, 'error reactivating project in docstore', { - project_id, + project_id: projectId, }) return callback(err) } - ProjectUpdateHandler.markAsActive(project_id, callback) + ProjectUpdateHandler.markAsActive(projectId, callback) }) } ) @@ -85,7 +84,7 @@ module.exports = InactiveProjectManager = { function (err) { if (err) { logger.err( - { project_id: project._id, err }, + { projectId: project._id, err }, 'unable to deactivate project' ) } @@ -106,15 +105,15 @@ module.exports = InactiveProjectManager = { }) }, - deactivateProject(project_id, callback) { - logger.debug({ project_id }, 'deactivating inactive project') + deactivateProject(projectId, callback) { + logger.debug({ projectId }, 'deactivating inactive project') const jobs = [ - cb => DocstoreManager.archiveProject(project_id, cb), - cb => ProjectUpdateHandler.markAsInactive(project_id, cb), + cb => DocstoreManager.archiveProject(projectId, cb), + cb => ProjectUpdateHandler.markAsInactive(projectId, cb), ] async.series(jobs, function (err) { if (err != null) { - logger.warn({ err, project_id }, 'error deactivating project') + logger.warn({ err, projectId }, 'error deactivating project') } callback(err) }) diff --git a/services/web/app/src/Features/LinkedFiles/LinkedFilesController.js b/services/web/app/src/Features/LinkedFiles/LinkedFilesController.js index bb3840d1dc..9f28dbf2bc 100644 --- a/services/web/app/src/Features/LinkedFiles/LinkedFilesController.js +++ b/services/web/app/src/Features/LinkedFiles/LinkedFilesController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, */ @@ -65,9 +64,9 @@ module.exports = LinkedFilesController = { }, createLinkedFile(req, res, next) { - const { project_id } = req.params - const { name, provider, data, parent_folder_id } = req.body - const user_id = SessionManager.getLoggedInUserId(req.session) + const { project_id: projectId } = req.params + const { name, provider, data, parent_folder_id: parentFolderId } = req.body + const userId = SessionManager.getLoggedInUserId(req.session) const Agent = LinkedFilesController._getAgent(provider) if (Agent == null) { @@ -77,11 +76,11 @@ module.exports = LinkedFilesController = { data.provider = provider return Agent.createLinkedFile( - project_id, + projectId, data, name, - parent_folder_id, - user_id, + parentFolderId, + userId, function (err, newFileId) { if (err != null) { return LinkedFilesController.handleError(err, req, res, next) @@ -92,12 +91,12 @@ module.exports = LinkedFilesController = { }, refreshLinkedFile(req, res, next) { - const { project_id, file_id } = req.params - const user_id = SessionManager.getLoggedInUserId(req.session) + const { project_id: projectId, file_id: fileId } = req.params + const userId = SessionManager.getLoggedInUserId(req.session) return LinkedFilesHandler.getFileById( - project_id, - file_id, + projectId, + fileId, function (err, file, path, parentFolder) { if (err != null) { return next(err) @@ -114,18 +113,18 @@ module.exports = LinkedFilesController = { return res.sendStatus(409) } const { provider } = linkedFileData - const parent_folder_id = parentFolder._id + const parentFolderId = parentFolder._id const Agent = LinkedFilesController._getAgent(provider) if (Agent == null) { return res.sendStatus(400) } return Agent.refreshLinkedFile( - project_id, + projectId, linkedFileData, name, - parent_folder_id, - user_id, + parentFolderId, + userId, function (err, newFileId) { if (err != null) { return LinkedFilesController.handleError(err, req, res, next) diff --git a/services/web/app/src/Features/LinkedFiles/LinkedFilesHandler.js b/services/web/app/src/Features/LinkedFiles/LinkedFilesHandler.js index f94f2ee442..c98b087db3 100644 --- a/services/web/app/src/Features/LinkedFiles/LinkedFilesHandler.js +++ b/services/web/app/src/Features/LinkedFiles/LinkedFilesHandler.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-unused-vars, @@ -25,14 +24,14 @@ const { } = require('./LinkedFilesErrors') module.exports = LinkedFilesHandler = { - getFileById(project_id, file_id, callback) { + getFileById(projectId, fileId, callback) { if (callback == null) { callback = function () {} } ProjectLocator.findElement( { - project_id, - element_id: file_id, + project_id: projectId, + element_id: fileId, type: 'file', }, function (err, file, path, parentFolder) { @@ -83,69 +82,65 @@ module.exports = LinkedFilesHandler = { }, importFromStream( - project_id, + projectId, readStream, linkedFileData, name, - parent_folder_id, - user_id, + parentFolderId, + userId, callback ) { if (callback == null) { callback = function () {} } callback = _.once(callback) - FileWriter.writeStreamToDisk( - project_id, - readStream, - function (err, fsPath) { - if (err != null) { - return callback(err) - } - EditorController.upsertFile( - project_id, - parent_folder_id, - name, - fsPath, - linkedFileData, - 'upload', - user_id, - (err, file) => { - if (err != null) { - return callback(err) - } - callback(null, file) - } - ) - } - ) - }, - - importContent( - project_id, - content, - linkedFileData, - name, - parent_folder_id, - user_id, - callback - ) { - if (callback == null) { - callback = function () {} - } - callback = _.once(callback) - FileWriter.writeContentToDisk(project_id, content, function (err, fsPath) { + FileWriter.writeStreamToDisk(projectId, readStream, function (err, fsPath) { if (err != null) { return callback(err) } EditorController.upsertFile( - project_id, - parent_folder_id, + projectId, + parentFolderId, name, fsPath, linkedFileData, 'upload', - user_id, + userId, + (err, file) => { + if (err != null) { + return callback(err) + } + callback(null, file) + } + ) + }) + }, + + importContent( + projectId, + content, + linkedFileData, + name, + parentFolderId, + userId, + callback + ) { + if (callback == null) { + callback = function () {} + } + callback = _.once(callback) + FileWriter.writeContentToDisk(projectId, content, function (err, fsPath) { + if (err != null) { + return callback(err) + } + EditorController.upsertFile( + projectId, + parentFolderId, + name, + fsPath, + linkedFileData, + 'upload', + userId, (err, file) => { if (err != null) { return callback(err) diff --git a/services/web/app/src/Features/LinkedFiles/ProjectFileAgent.js b/services/web/app/src/Features/LinkedFiles/ProjectFileAgent.js index 3be77c9283..c25a3c667e 100644 --- a/services/web/app/src/Features/LinkedFiles/ProjectFileAgent.js +++ b/services/web/app/src/Features/LinkedFiles/ProjectFileAgent.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-unused-vars, @@ -33,52 +32,52 @@ const { module.exports = ProjectFileAgent = { createLinkedFile( - project_id, + projectId, linkedFileData, name, - parent_folder_id, - user_id, + parentFolderId, + userId, callback ) { if (!this._canCreate(linkedFileData)) { return callback(new AccessDeniedError()) } return this._go( - project_id, + projectId, linkedFileData, name, - parent_folder_id, - user_id, + parentFolderId, + userId, callback ) }, refreshLinkedFile( - project_id, + projectId, linkedFileData, name, - parent_folder_id, - user_id, + parentFolderId, + userId, callback ) { return this._go( - project_id, + projectId, linkedFileData, name, - parent_folder_id, - user_id, + parentFolderId, + userId, callback ) }, - _prepare(project_id, linkedFileData, user_id, callback) { + _prepare(projectId, linkedFileData, userId, callback) { if (callback == null) { callback = function () {} } return this._checkAuth( - project_id, + projectId, linkedFileData, - user_id, + userId, (err, allowed) => { if (err != null) { return callback(err) @@ -94,12 +93,12 @@ module.exports = ProjectFileAgent = { ) }, - _go(project_id, linkedFileData, name, parent_folder_id, user_id, callback) { + _go(projectId, linkedFileData, name, parentFolderId, userId, callback) { linkedFileData = this._sanitizeData(linkedFileData) return this._prepare( - project_id, + projectId, linkedFileData, - user_id, + userId, (err, linkedFileData) => { if (err != null) { return callback(err) @@ -109,26 +108,26 @@ module.exports = ProjectFileAgent = { } return this._getEntity( linkedFileData, - user_id, - (err, source_project, entity, type) => { + userId, + (err, sourceProject, entity, type) => { if (err != null) { return callback(err) } if (type === 'doc') { return DocstoreManager.getDoc( - source_project._id, + sourceProject._id, entity._id, function (err, lines) { if (err != null) { return callback(err) } return LinkedFilesHandler.importContent( - project_id, + projectId, lines.join('\n'), linkedFileData, name, - parent_folder_id, - user_id, + parentFolderId, + userId, function (err, file) { if (err != null) { return callback(err) @@ -140,7 +139,7 @@ module.exports = ProjectFileAgent = { ) // Created } else if (type === 'file') { return FileStoreHandler.getFileStream( - source_project._id, + sourceProject._id, entity._id, null, function (err, fileStream) { @@ -148,12 +147,12 @@ module.exports = ProjectFileAgent = { return callback(err) } return LinkedFilesHandler.importFromStream( - project_id, + projectId, fileStream, linkedFileData, name, - parent_folder_id, - user_id, + parentFolderId, + userId, function (err, file) { if (err != null) { return callback(err) @@ -172,27 +171,27 @@ module.exports = ProjectFileAgent = { ) }, - _getEntity(linkedFileData, current_user_id, callback) { + _getEntity(linkedFileData, currentUserId, callback) { if (callback == null) { callback = function () {} } callback = _.once(callback) - const { source_entity_path } = linkedFileData + const { source_entity_path: sourceEntityPath } = linkedFileData return this._getSourceProject(linkedFileData, function (err, project) { if (err != null) { return callback(err) } - const source_project_id = project._id + const sourceProjectId = project._id return DocumentUpdaterHandler.flushProjectToMongo( - source_project_id, + sourceProjectId, function (err) { if (err != null) { return callback(err) } return ProjectLocator.findElementByPath( { - project_id: source_project_id, - path: source_entity_path, + project_id: sourceProjectId, + path: sourceEntityPath, exactCaseMatch: true, }, function (err, entity, type) { @@ -234,7 +233,7 @@ module.exports = ProjectFileAgent = { _getSourceProject: LinkedFilesHandler.getSourceProject, - _checkAuth(project_id, data, current_user_id, callback) { + _checkAuth(projectId, data, currentUserId, callback) { if (callback == null) { callback = function () {} } @@ -247,7 +246,7 @@ module.exports = ProjectFileAgent = { return callback(err) } return AuthorizationManager.canUserReadProject( - current_user_id, + currentUserId, project._id, null, function (err, canRead) { diff --git a/services/web/app/src/Features/Metadata/MetaController.js b/services/web/app/src/Features/Metadata/MetaController.js index 6697af93df..2fcc7583c7 100644 --- a/services/web/app/src/Features/Metadata/MetaController.js +++ b/services/web/app/src/Features/Metadata/MetaController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, */ @@ -19,53 +18,49 @@ const logger = require('@overleaf/logger') module.exports = MetaController = { getMetadata(req, res, next) { - const { project_id } = req.params - logger.debug({ project_id }, 'getting all labels for project') + const { project_id: projectId } = req.params + logger.debug({ projectId }, 'getting all labels for project') return MetaHandler.getAllMetaForProject( - project_id, + projectId, function (err, projectMeta) { if (err != null) { OError.tag( err, '[MetaController] error getting all labels from project', { - project_id, + project_id: projectId, } ) return next(err) } - return res.json({ projectId: project_id, projectMeta }) + return res.json({ projectId, projectMeta }) } ) }, broadcastMetadataForDoc(req, res, next) { - const { project_id } = req.params - const { doc_id } = req.params + const { project_id: projectId } = req.params + const { doc_id: docId } = req.params const { broadcast } = req.body - logger.debug({ project_id, doc_id, broadcast }, 'getting labels for doc') - return MetaHandler.getMetaForDoc( - project_id, - doc_id, - function (err, docMeta) { - if (err != null) { - OError.tag(err, '[MetaController] error getting labels from doc', { - project_id, - doc_id, - }) - return next(err) - } - // default to broadcasting, unless explicitly disabled (for backwards compatibility) - if (broadcast !== false) { - EditorRealTimeController.emitToRoom(project_id, 'broadcastDocMeta', { - docId: doc_id, - meta: docMeta, - }) - return res.sendStatus(200) - } else { - return res.json({ docId: doc_id, meta: docMeta }) - } + logger.debug({ projectId, docId, broadcast }, 'getting labels for doc') + return MetaHandler.getMetaForDoc(projectId, docId, function (err, docMeta) { + if (err != null) { + OError.tag(err, '[MetaController] error getting labels from doc', { + project_id: projectId, + doc_id: docId, + }) + return next(err) } - ) + // default to broadcasting, unless explicitly disabled (for backwards compatibility) + if (broadcast !== false) { + EditorRealTimeController.emitToRoom(projectId, 'broadcastDocMeta', { + docId, + meta: docMeta, + }) + return res.sendStatus(200) + } else { + return res.json({ docId, meta: docMeta }) + } + }) }, } diff --git a/services/web/app/src/Features/Metadata/MetaHandler.js b/services/web/app/src/Features/Metadata/MetaHandler.js index a1849068f4..0b01e4ad9f 100644 --- a/services/web/app/src/Features/Metadata/MetaHandler.js +++ b/services/web/app/src/Features/Metadata/MetaHandler.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-cond-assign, @@ -82,19 +81,19 @@ module.exports = MetaHandler = { let pkg const docMeta = { labels: [], packages: {} } const packages = [] - const label_re = MetaHandler.labelRegex() - const package_re = MetaHandler.usepackageRegex() - const req_package_re = MetaHandler.ReqPackageRegex() + const labelRe = MetaHandler.labelRegex() + const packageRe = MetaHandler.usepackageRegex() + const reqPackageRe = MetaHandler.ReqPackageRegex() for (const line of Array.from(lines)) { let labelMatch let clean, messy, packageMatch - while ((labelMatch = label_re.exec(line))) { + while ((labelMatch = labelRe.exec(line))) { let label if ((label = labelMatch[1])) { docMeta.labels.push(label) } } - while ((packageMatch = package_re.exec(line))) { + while ((packageMatch = packageRe.exec(line))) { if ((messy = packageMatch[1])) { for (pkg of Array.from(messy.split(','))) { if ((clean = pkg.trim())) { @@ -103,7 +102,7 @@ module.exports = MetaHandler = { } } } - while ((packageMatch = req_package_re.exec(line))) { + while ((packageMatch = reqPackageRe.exec(line))) { if ((messy = packageMatch[1])) { for (pkg of Array.from(messy.split(','))) { if ((clean = pkg.trim())) { diff --git a/services/web/app/src/Features/Project/ProjectApiController.js b/services/web/app/src/Features/Project/ProjectApiController.js index 8bab741df1..a0899f5e71 100644 --- a/services/web/app/src/Features/Project/ProjectApiController.js +++ b/services/web/app/src/Features/Project/ProjectApiController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, */ @@ -16,9 +15,9 @@ const logger = require('@overleaf/logger') module.exports = { getProjectDetails(req, res, next) { - const { project_id } = req.params + const { project_id: projectId } = req.params return ProjectDetailsHandler.getDetails( - project_id, + projectId, function (err, projDetails) { if (err != null) { return next(err) diff --git a/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js b/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js index c03e060822..2b92d606ab 100644 --- a/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js +++ b/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, */ @@ -17,38 +16,44 @@ const { Project } = require('../../models/Project') module.exports = ProjectCollabratecDetailsHandler = { initializeCollabratecProject( - project_id, - user_id, - collabratec_document_id, - collabratec_privategroup_id, + projectId, + userId, + collabratecDocumentId, + collabratecPrivategroupId, callback ) { if (callback == null) { callback = function () {} } ProjectCollabratecDetailsHandler.setCollabratecUsers( - project_id, - [{ user_id, collabratec_document_id, collabratec_privategroup_id }], + projectId, + [ + { + user_id: userId, + collabratec_document_id: collabratecDocumentId, + collabratec_privategroup_id: collabratecPrivategroupId, + }, + ], callback ) }, - isLinkedCollabratecUserProject(project_id, user_id, callback) { + isLinkedCollabratecUserProject(projectId, userId, callback) { if (callback == null) { callback = function () {} } try { - project_id = ObjectId(project_id) - user_id = ObjectId(user_id) + projectId = ObjectId(projectId) + userId = ObjectId(userId) } catch (error) { const err = error return callback(err) } const query = { - _id: project_id, + _id: projectId, collabratecUsers: { $elemMatch: { - user_id, + user_id: userId, }, }, } @@ -61,28 +66,28 @@ module.exports = ProjectCollabratecDetailsHandler = { }, linkCollabratecUserProject( - project_id, - user_id, - collabratec_document_id, + projectId, + userId, + collabratecDocumentId, callback ) { if (callback == null) { callback = function () {} } try { - project_id = ObjectId(project_id) - user_id = ObjectId(user_id) + projectId = ObjectId(projectId) + userId = ObjectId(userId) } catch (error) { const err = error return callback(err) } const query = { - _id: project_id, + _id: projectId, collabratecUsers: { $not: { $elemMatch: { - collabratec_document_id, - user_id, + collabratec_document_id: collabratecDocumentId, + user_id: userId, }, }, }, @@ -90,75 +95,75 @@ module.exports = ProjectCollabratecDetailsHandler = { const update = { $push: { collabratecUsers: { - collabratec_document_id, - user_id, + collabratec_document_id: collabratecDocumentId, + user_id: userId, }, }, } Project.updateOne(query, update, callback) }, - setCollabratecUsers(project_id, collabratec_users, callback) { + setCollabratecUsers(projectId, collabratecUsers, callback) { let err if (callback == null) { callback = function () {} } try { - project_id = ObjectId(project_id) + projectId = ObjectId(projectId) } catch (error) { err = error return callback(err) } - if (!Array.isArray(collabratec_users)) { + if (!Array.isArray(collabratecUsers)) { callback(new Error('collabratec_users must be array')) } - for (const collabratec_user of Array.from(collabratec_users)) { + for (const collabratecUser of Array.from(collabratecUsers)) { try { - collabratec_user.user_id = ObjectId(collabratec_user.user_id) + collabratecUser.user_id = ObjectId(collabratecUser.user_id) } catch (error1) { err = error1 return callback(err) } } - const update = { $set: { collabratecUsers: collabratec_users } } - Project.updateOne({ _id: project_id }, update, callback) + const update = { $set: { collabratecUsers } } + Project.updateOne({ _id: projectId }, update, callback) }, - unlinkCollabratecUserProject(project_id, user_id, callback) { + unlinkCollabratecUserProject(projectId, userId, callback) { if (callback == null) { callback = function () {} } try { - project_id = ObjectId(project_id) - user_id = ObjectId(user_id) + projectId = ObjectId(projectId) + userId = ObjectId(userId) } catch (error) { const err = error return callback(err) } - const query = { _id: project_id } + const query = { _id: projectId } const update = { $pull: { collabratecUsers: { - user_id, + user_id: userId, }, }, } Project.updateOne(query, update, callback) }, - updateCollabratecUserIds(old_user_id, new_user_id, callback) { + updateCollabratecUserIds(oldUserId, newUserId, callback) { if (callback == null) { callback = function () {} } try { - old_user_id = ObjectId(old_user_id) - new_user_id = ObjectId(new_user_id) + oldUserId = ObjectId(oldUserId) + newUserId = ObjectId(newUserId) } catch (error) { const err = error return callback(err) } - const query = { 'collabratecUsers.user_id': old_user_id } - const update = { $set: { 'collabratecUsers.$.user_id': new_user_id } } + const query = { 'collabratecUsers.user_id': oldUserId } + const update = { $set: { 'collabratecUsers.$.user_id': newUserId } } Project.updateMany(query, update, callback) }, } diff --git a/services/web/app/src/Features/Project/ProjectDeleter.js b/services/web/app/src/Features/Project/ProjectDeleter.js index a71fe69e28..3716a11980 100644 --- a/services/web/app/src/Features/Project/ProjectDeleter.js +++ b/services/web/app/src/Features/Project/ProjectDeleter.js @@ -57,7 +57,7 @@ module.exports = { async function markAsDeletedByExternalSource(projectId) { logger.debug( - { project_id: projectId }, + { projectId }, 'marking project as deleted by external data source' ) await Project.updateOne( @@ -274,7 +274,7 @@ async function deleteProject(projectId, options = {}) { throw err } - logger.debug({ project_id: projectId }, 'successfully deleted project') + logger.debug({ projectId }, 'successfully deleted project') } async function undeleteProject(projectId, options = {}) { diff --git a/services/web/app/src/Features/Project/ProjectRootDocManager.js b/services/web/app/src/Features/Project/ProjectRootDocManager.js index 0f712787fb..c7aceb6f4d 100644 --- a/services/web/app/src/Features/Project/ProjectRootDocManager.js +++ b/services/web/app/src/Features/Project/ProjectRootDocManager.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-unused-vars, @@ -27,11 +26,11 @@ const _ = require('underscore') const { promisifyAll } = require('../../util/promises') module.exports = ProjectRootDocManager = { - setRootDocAutomatically(project_id, callback) { + setRootDocAutomatically(projectId, callback) { if (callback == null) { callback = function () {} } - return ProjectEntityHandler.getAllDocs(project_id, function (error, docs) { + return ProjectEntityHandler.getAllDocs(projectId, function (error, docs) { if (error != null) { return callback(error) } @@ -55,11 +54,11 @@ module.exports = ProjectRootDocManager = { } ) - return async.series(jobs, function (root_doc_id) { - if (root_doc_id != null) { + return async.series(jobs, function (rootDocId) { + if (rootDocId != null) { return ProjectEntityUpdateHandler.setRootDoc( - project_id, - root_doc_id, + projectId, + rootDocId, callback ) } else { @@ -130,14 +129,14 @@ module.exports = ProjectRootDocManager = { return null }, - setRootDocFromName(project_id, rootDocName, callback) { + setRootDocFromName(projectId, rootDocName, callback) { if (callback == null) { callback = function () {} } return ProjectEntityHandler.getAllDocPathsFromProjectById( - project_id, + projectId, function (error, docPaths) { - let doc_id, path + let docId, path if (error != null) { return callback(error) } @@ -148,28 +147,28 @@ module.exports = ProjectRootDocManager = { rootDocName = `/${rootDocName}` } // find the root doc from the filename - let root_doc_id = null - for (doc_id in docPaths) { + let rootDocId = null + for (docId in docPaths) { // docpaths have a leading / so allow matching "folder/filename" and "/folder/filename" - path = docPaths[doc_id] + path = docPaths[docId] if (path === rootDocName) { - root_doc_id = doc_id + rootDocId = docId } } // try a basename match if there was no match - if (!root_doc_id) { - for (doc_id in docPaths) { - path = docPaths[doc_id] + if (!rootDocId) { + for (docId in docPaths) { + path = docPaths[docId] if (Path.basename(path) === Path.basename(rootDocName)) { - root_doc_id = doc_id + rootDocId = docId } } } // set the root doc id if we found a match - if (root_doc_id != null) { + if (rootDocId != null) { return ProjectEntityUpdateHandler.setRootDoc( - project_id, - root_doc_id, + projectId, + rootDocId, callback ) } else { @@ -179,12 +178,12 @@ module.exports = ProjectRootDocManager = { ) }, - ensureRootDocumentIsSet(project_id, callback) { + ensureRootDocumentIsSet(projectId, callback) { if (callback == null) { callback = function () {} } return ProjectGetter.getProject( - project_id, + projectId, { rootDoc_id: 1 }, function (error, project) { if (error != null) { @@ -198,7 +197,7 @@ module.exports = ProjectRootDocManager = { return callback() } else { return ProjectRootDocManager.setRootDocAutomatically( - project_id, + projectId, callback ) } @@ -210,9 +209,9 @@ module.exports = ProjectRootDocManager = { * @param {ObjectId | string} project_id * @param {Function} callback */ - ensureRootDocumentIsValid(project_id, callback) { + ensureRootDocumentIsValid(projectId, callback) { ProjectGetter.getProjectWithoutDocLines( - project_id, + projectId, function (error, project) { if (error != null) { return callback(error) @@ -227,9 +226,9 @@ module.exports = ProjectRootDocManager = { project.rootDoc_id, (err, docPath) => { if (docPath) return callback() - ProjectEntityUpdateHandler.unsetRootDoc(project_id, () => + ProjectEntityUpdateHandler.unsetRootDoc(projectId, () => ProjectRootDocManager.setRootDocAutomatically( - project_id, + projectId, callback ) ) @@ -237,7 +236,7 @@ module.exports = ProjectRootDocManager = { ) } else { return ProjectRootDocManager.setRootDocAutomatically( - project_id, + projectId, callback ) } diff --git a/services/web/app/src/Features/Project/ProjectUpdateHandler.js b/services/web/app/src/Features/Project/ProjectUpdateHandler.js index 97c0ac2bd9..98495a575f 100644 --- a/services/web/app/src/Features/Project/ProjectUpdateHandler.js +++ b/services/web/app/src/Features/Project/ProjectUpdateHandler.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, no-unused-vars, */ @@ -55,8 +54,8 @@ const ProjectUpdateHandler = { Project.updateOne(conditions, update, {}, callback) }, - markAsOpened(project_id, callback) { - const conditions = { _id: project_id } + markAsOpened(projectId, callback) { + const conditions = { _id: projectId } const update = { lastOpened: Date.now() } Project.updateOne(conditions, update, {}, function (err) { if (callback != null) { @@ -65,8 +64,8 @@ const ProjectUpdateHandler = { }) }, - markAsInactive(project_id, callback) { - const conditions = { _id: project_id } + markAsInactive(projectId, callback) { + const conditions = { _id: projectId } const update = { active: false } Project.updateOne(conditions, update, {}, function (err) { if (callback != null) { @@ -75,8 +74,8 @@ const ProjectUpdateHandler = { }) }, - markAsActive(project_id, callback) { - const conditions = { _id: project_id } + markAsActive(projectId, callback) { + const conditions = { _id: projectId } const update = { active: true } Project.updateOne(conditions, update, {}, function (err) { if (callback != null) { diff --git a/services/web/app/src/Features/ServerAdmin/AdminController.js b/services/web/app/src/Features/ServerAdmin/AdminController.js index 5148a25f88..c077e6fc31 100644 --- a/services/web/app/src/Features/ServerAdmin/AdminController.js +++ b/services/web/app/src/Features/ServerAdmin/AdminController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len */ @@ -144,8 +143,8 @@ const AdminController = { }, pollDropboxForUser(req, res) { - const { user_id } = req.body - return TpdsUpdateSender.pollDropboxForUser(user_id, () => + const { user_id: userId } = req.body + return TpdsUpdateSender.pollDropboxForUser(userId, () => res.sendStatus(200) ) }, diff --git a/services/web/app/src/Features/Subscription/RecurlyWrapper.js b/services/web/app/src/Features/Subscription/RecurlyWrapper.js index 6a6086866c..9f8bfb1a1e 100644 --- a/services/web/app/src/Features/Subscription/RecurlyWrapper.js +++ b/services/web/app/src/Features/Subscription/RecurlyWrapper.js @@ -43,7 +43,7 @@ const RecurlyWrapper = { checkAccountExists(cache, next) { const { user } = cache logger.debug( - { user_id: user._id }, + { userId: user._id }, 'checking if recurly account exists for user' ) RecurlyWrapper.apiRequest( @@ -66,16 +66,13 @@ const RecurlyWrapper = { if (response.statusCode === 404) { // actually not an error in this case, just no existing account logger.debug( - { user_id: user._id }, + { userId: user._id }, 'user does not currently exist in recurly, proceed' ) cache.userExists = false return next(null, cache) } - logger.debug( - { user_id: user._id }, - 'user appears to exist in recurly' - ) + logger.debug({ userId: user._id }, 'user appears to exist in recurly') RecurlyWrapper._parseAccountXml( responseBody, function (err, account) { @@ -158,7 +155,7 @@ const RecurlyWrapper = { createBillingInfo(cache, next) { const { user } = cache const { recurlyTokenIds } = cache - logger.debug({ user_id: user._id }, 'creating billing info in recurly') + logger.debug({ userId: user._id }, 'creating billing info in recurly') const accountCode = cache?.account?.account_code if (!accountCode) { return next(new Error('no account code at createBillingInfo stage')) @@ -211,7 +208,7 @@ const RecurlyWrapper = { const { user } = cache const { subscriptionDetails } = cache logger.debug( - { user_id: user._id }, + { userId: user._id }, 'setting billing address and company info in recurly' ) const accountCode = cache?.account?.account_code @@ -279,7 +276,7 @@ const RecurlyWrapper = { createSubscription(cache, next) { const { user } = cache const { subscriptionDetails } = cache - logger.debug({ user_id: user._id }, 'creating subscription in recurly') + logger.debug({ userId: user._id }, 'creating subscription in recurly') const data = { plan_code: subscriptionDetails.plan_code, currency: subscriptionDetails.currencyCode, @@ -344,7 +341,7 @@ const RecurlyWrapper = { callback ) { logger.debug( - { user_id: user._id }, + { userId: user._id }, 'starting process of creating paypal subscription' ) // We use `async.waterfall` to run each of these actions in sequence @@ -374,7 +371,7 @@ const RecurlyWrapper = { return callback(err) } logger.debug( - { user_id: user._id }, + { userId: user._id }, 'done creating paypal subscription for user' ) callback(null, result.subscription) @@ -444,7 +441,7 @@ const RecurlyWrapper = { createSubscription(user, subscriptionDetails, recurlyTokenIds, callback) { const { isPaypal } = subscriptionDetails logger.debug( - { user_id: user._id, isPaypal }, + { userId: user._id, isPaypal }, 'setting up subscription in recurly' ) const fn = isPaypal diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index 384c34c354..1153dacf66 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionController.js @@ -451,7 +451,7 @@ async function createSubscription(req, res) { await LimitationsManager.promises.userHasV1OrV2Subscription(user) if (hasSubscription) { - logger.warn({ user_id: user._id }, 'user already has subscription') + logger.warn({ userId: user._id }, 'user already has subscription') return res.sendStatus(409) // conflict } @@ -477,7 +477,7 @@ async function createSubscription(req, res) { ) } else { logger.warn( - { err, user_id: user._id }, + { err, userId: user._id }, 'something went wrong creating subscription' ) throw err @@ -553,7 +553,7 @@ async function _successfulSubscriptionAngular(req, res) { function cancelSubscription(req, res, next) { const user = SessionManager.getSessionUser(req.session) - logger.debug({ user_id: user._id }, 'canceling subscription') + logger.debug({ userId: user._id }, 'canceling subscription') SubscriptionHandler.cancelSubscription(user, function (err) { if (err) { OError.tag(err, 'something went wrong canceling subscription', { @@ -627,12 +627,12 @@ function updateSubscription(req, res, next) { if (planCode == null) { const err = new Error('plan_code is not defined') logger.warn( - { user_id: user._id, err, planCode, origin, body: req.body }, + { userId: user._id, err, planCode, origin, body: req.body }, '[Subscription] error in updateSubscription form' ) return next(err) } - logger.debug({ planCode, user_id: user._id }, 'updating subscription') + logger.debug({ planCode, userId: user._id }, 'updating subscription') SubscriptionHandler.updateSubscription(user, planCode, null, function (err) { if (err) { OError.tag(err, 'something went wrong updating subscription', { @@ -646,7 +646,7 @@ function updateSubscription(req, res, next) { function cancelPendingSubscriptionChange(req, res, next) { const user = SessionManager.getSessionUser(req.session) - logger.debug({ user_id: user._id }, 'canceling pending subscription change') + logger.debug({ userId: user._id }, 'canceling pending subscription change') SubscriptionHandler.cancelPendingSubscriptionChange(user, function (err) { if (err) { OError.tag( @@ -678,7 +678,7 @@ function updateAccountEmailAddress(req, res, next) { function reactivateSubscription(req, res, next) { const user = SessionManager.getSessionUser(req.session) - logger.debug({ user_id: user._id }, 'reactivating subscription') + logger.debug({ userId: user._id }, 'reactivating subscription') SubscriptionHandler.reactivateSubscription(user, function (err) { if (err) { OError.tag(err, 'something went wrong reactivating subscription', { @@ -775,7 +775,7 @@ function processUpgradeToAnnualPlan(req, res, next) { const couponCode = Settings.coupon_codes.upgradeToAnnualPromo[planName] const annualPlanName = `${planName}-annual` logger.debug( - { user_id: user._id, planName: annualPlanName }, + { userId: user._id, planName: annualPlanName }, 'user is upgrading to annual billing with discount' ) return SubscriptionHandler.updateSubscription( diff --git a/services/web/app/src/Features/Subscription/SubscriptionGroupController.js b/services/web/app/src/Features/Subscription/SubscriptionGroupController.js index 32203c3276..7e9a3a2579 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionGroupController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionGroupController.js @@ -8,7 +8,7 @@ function removeUserFromGroup(req, res, next) { const subscription = req.entity const userToRemoveId = req.params.user_id logger.debug( - { subscriptionId: subscription._id, userToRemove_id: userToRemoveId }, + { subscriptionId: subscription._id, userToRemoveId }, 'removing user from group subscription' ) SubscriptionGroupHandler.removeUserFromGroup( @@ -44,7 +44,7 @@ function removeSelfFromGroup(req, res, next) { function (error) { if (error) { logger.err( - { err: error, userToRemove_id: userToRemoveId, subscriptionId }, + { err: error, userToRemoveId, subscriptionId }, 'error removing self from group' ) return res.sendStatus(500) diff --git a/services/web/app/src/Features/Subscription/SubscriptionHandler.js b/services/web/app/src/Features/Subscription/SubscriptionHandler.js index 88c475de55..6b04c96f46 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionHandler.js +++ b/services/web/app/src/Features/Subscription/SubscriptionHandler.js @@ -80,7 +80,7 @@ function updateSubscription(user, planCode, couponCode, callback) { function (err, hasSubscription, subscription) { if (err) { logger.warn( - { err, user_id: user._id, hasSubscription }, + { err, userId: user._id, hasSubscription }, 'there was an error checking user v2 subscription' ) } @@ -183,7 +183,7 @@ function cancelSubscription(user, callback) { function (err, hasSubscription, subscription) { if (err) { logger.warn( - { err, user_id: user._id, hasSubscription }, + { err, userId: user._id, hasSubscription }, 'there was an error checking user v2 subscription' ) } @@ -220,7 +220,7 @@ function reactivateSubscription(user, callback) { function (err, hasSubscription, subscription) { if (err) { logger.warn( - { err, user_id: user._id, hasSubscription }, + { err, userId: user._id, hasSubscription }, 'there was an error checking user v2 subscription' ) } diff --git a/services/web/app/src/Features/Templates/TemplatesController.js b/services/web/app/src/Features/Templates/TemplatesController.js index 3dd29699ca..ff6c349c01 100644 --- a/services/web/app/src/Features/Templates/TemplatesController.js +++ b/services/web/app/src/Features/Templates/TemplatesController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, */ @@ -47,7 +46,7 @@ module.exports = TemplatesController = { }, createProjectFromV1Template(req, res, next) { - const user_id = SessionManager.getLoggedInUserId(req.session) + const userId = SessionManager.getLoggedInUserId(req.session) return TemplatesManager.createProjectFromV1Template( req.body.brandVariationId, req.body.compiler, @@ -55,7 +54,7 @@ module.exports = TemplatesController = { req.body.templateId, req.body.templateName, req.body.templateVersionId, - user_id, + userId, req.body.imageName, function (err, project) { if (err != null) { diff --git a/services/web/app/src/Features/Templates/TemplatesManager.js b/services/web/app/src/Features/Templates/TemplatesManager.js index e861cfdb3f..f3b506a28b 100644 --- a/services/web/app/src/Features/Templates/TemplatesManager.js +++ b/services/web/app/src/Features/Templates/TemplatesManager.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, */ // TODO: This file was created by bulk-decaffeinate. @@ -35,7 +34,7 @@ const TemplatesManager = { templateId, templateName, templateVersionId, - user_id, + userId, imageName, _callback ) { @@ -73,7 +72,7 @@ const TemplatesManager = { return callback(new Error('get zip failed')) } ProjectUploadManager.createProjectFromZipArchiveWithName( - user_id, + userId, projectName, dumpPath, attributes, @@ -129,33 +128,33 @@ const TemplatesManager = { }) }, - _setCompiler(project_id, compiler, callback) { + _setCompiler(projectId, compiler, callback) { if (compiler == null) { return callback() } - ProjectOptionsHandler.setCompiler(project_id, compiler, callback) + ProjectOptionsHandler.setCompiler(projectId, compiler, callback) }, - _setImage(project_id, imageName, callback) { + _setImage(projectId, imageName, callback) { if (!imageName) { imageName = 'wl_texlive:2018.1' } - ProjectOptionsHandler.setImageName(project_id, imageName, callback) + ProjectOptionsHandler.setImageName(projectId, imageName, callback) }, - _setMainFile(project_id, mainFile, callback) { + _setMainFile(projectId, mainFile, callback) { if (mainFile == null) { return callback() } - ProjectRootDocManager.setRootDocFromName(project_id, mainFile, callback) + ProjectRootDocManager.setRootDocFromName(projectId, mainFile, callback) }, - _setBrandVariationId(project_id, brandVariationId, callback) { + _setBrandVariationId(projectId, brandVariationId, callback) { if (brandVariationId == null) { return callback() } ProjectOptionsHandler.setBrandVariationId( - project_id, + projectId, brandVariationId, callback ) diff --git a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.js b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.js index 91936bd6b4..5d39a66c58 100644 --- a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.js +++ b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.js @@ -89,7 +89,7 @@ async function deleteUpdate(userId, projectId, projectName, path, source) { const project = activeProjects[0] if (path === '/') { logger.debug( - { userId, filePath: path, projectName, project_id: project._id }, + { userId, filePath: path, projectName, projectId: project._id }, 'project found for delete update, path is root so marking project as deleted' ) await ProjectDeleter.promises.markAsDeletedByExternalSource(project._id) diff --git a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js index aceb641995..61477a501e 100644 --- a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js +++ b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js @@ -190,7 +190,7 @@ async function deleteProject(params) { ) if (!response.ok) { logger.error( - { statusCode: response.status, project_id: projectId }, + { statusCode: response.status, projectId }, 'error deleting project in third party datastore (project_archiver)' ) return false diff --git a/services/web/app/src/Features/Uploads/ProjectUploadController.js b/services/web/app/src/Features/Uploads/ProjectUploadController.js index b6fe89ad2b..f64a422674 100644 --- a/services/web/app/src/Features/Uploads/ProjectUploadController.js +++ b/services/web/app/src/Features/Uploads/ProjectUploadController.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, */ @@ -39,11 +38,11 @@ const upload = multer( module.exports = ProjectUploadController = { uploadProject(req, res, next) { const timer = new metrics.Timer('project-upload') - const user_id = SessionManager.getLoggedInUserId(req.session) + const userId = SessionManager.getLoggedInUserId(req.session) const { originalname, path } = req.file const name = Path.basename(originalname, '.zip') return ProjectUploadManager.createProjectFromZipArchive( - user_id, + userId, name, path, function (error, project) { @@ -76,11 +75,11 @@ module.exports = ProjectUploadController = { const timer = new metrics.Timer('file-upload') const name = req.file != null ? req.file.originalname : undefined const path = req.file != null ? req.file.path : undefined - const project_id = req.params.Project_id - const { folder_id } = req.query + const projectId = req.params.Project_id + const { folder_id: folderId } = req.query if (name == null || name.length === 0 || name.length > 150) { logger.err( - { projectId: project_id, fileName: name }, + { projectId, fileName: name }, 'bad name when trying to upload file' ) return res.status(422).json({ @@ -88,12 +87,12 @@ module.exports = ProjectUploadController = { error: 'invalid_filename', }) } - const user_id = SessionManager.getLoggedInUserId(req.session) + const userId = SessionManager.getLoggedInUserId(req.session) return FileSystemImportManager.addEntity( - user_id, - project_id, - folder_id, + userId, + projectId, + folderId, name, path, true, @@ -104,10 +103,10 @@ module.exports = ProjectUploadController = { logger.error( { err: error, - projectId: project_id, + projectId, filePath: path, fileName: name, - folderId: folder_id, + folderId, }, 'error uploading file' ) diff --git a/services/web/app/src/Features/User/UserSessionsManager.js b/services/web/app/src/Features/User/UserSessionsManager.js index 4190a7a3f9..8be80e1ae0 100644 --- a/services/web/app/src/Features/User/UserSessionsManager.js +++ b/services/web/app/src/Features/User/UserSessionsManager.js @@ -88,10 +88,7 @@ const UserSessionsManager = { } sessionKeys = _.filter(sessionKeys, k => !_.contains(exclude, k)) if (sessionKeys.length === 0) { - logger.debug( - { user_id: user._id }, - 'no other sessions found, returning' - ) + logger.debug({ userId: user._id }, 'no other sessions found, returning') return callback(null, []) } @@ -152,13 +149,13 @@ const UserSessionsManager = { ) if (keysToDelete.length === 0) { logger.debug( - { user_id: user._id }, + { userId: user._id }, 'no sessions in UserSessions set to delete, returning' ) return callback(null) } logger.debug( - { user_id: user._id, count: keysToDelete.length }, + { userId: user._id, count: keysToDelete.length }, 'deleting sessions for user' ) diff --git a/services/web/app/src/Features/V1/V1Handler.js b/services/web/app/src/Features/V1/V1Handler.js index 8a7f682600..5634804b58 100644 --- a/services/web/app/src/Features/V1/V1Handler.js +++ b/services/web/app/src/Features/V1/V1Handler.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, */ @@ -55,13 +54,13 @@ module.exports = V1Handler = { ) }, - doPasswordReset(v1_user_id, password, callback) { + doPasswordReset(v1UserId, password, callback) { return V1Api.request( { method: 'POST', url: '/api/v1/sharelatex/reset_password', json: { - user_id: v1_user_id, + user_id: v1UserId, password, }, expectedStatusCodes: [200], @@ -69,13 +68,13 @@ module.exports = V1Handler = { function (err, response, body) { if (err != null) { OError.tag(err, 'error while talking to v1 password reset api', { - v1_user_id, + v1_user_id: v1UserId, }) return callback(err, false) } if ([200].includes(response.statusCode)) { logger.debug( - { v1_user_id, changed: true }, + { v1UserId, changed: true }, 'got success response from v1 password reset api' ) return callback(null, true) diff --git a/services/web/app/src/infrastructure/ExpressLocals.js b/services/web/app/src/infrastructure/ExpressLocals.js index 7d1ed633b6..167e99a559 100644 --- a/services/web/app/src/infrastructure/ExpressLocals.js +++ b/services/web/app/src/infrastructure/ExpressLocals.js @@ -126,7 +126,7 @@ module.exports = function (webRouter, privateApiRouter, publicApiRouter) { const userId = SessionManager.getLoggedInUserId(req.session) if (cdnBlocked && req.session.cdnBlocked == null) { logger.debug( - { user_id: userId, ip: req != null ? req.ip : undefined }, + { userId, ip: req != null ? req.ip : undefined }, 'cdnBlocked for user, not using it and turning it off for future requets' ) Metrics.inc('no_cdn', 1, { diff --git a/services/web/app/src/util/bib2json.js b/services/web/app/src/util/bib2json.js index e9fd468e36..3ad0994fab 100644 --- a/services/web/app/src/util/bib2json.js +++ b/services/web/app/src/util/bib2json.js @@ -49,7 +49,7 @@ function BibtexParser(arg0, allowedKeys) { let parser = new BibtexParser(accumulator, allowedKeys) parser.parse(arg0) return { - entries: entries, + entries, errors: parser.getErrors(), } } diff --git a/services/web/modules/launchpad/app/src/LaunchpadController.js b/services/web/modules/launchpad/app/src/LaunchpadController.js index 39b3b18ab5..7718c1942e 100644 --- a/services/web/modules/launchpad/app/src/LaunchpadController.js +++ b/services/web/modules/launchpad/app/src/LaunchpadController.js @@ -185,7 +185,7 @@ module.exports = LaunchpadController = { AuthenticationController.setRedirectInSession(req, '/launchpad') logger.debug( - { email, user_id: user._id, authMethod }, + { email, userId: user._id, authMethod }, 'created first admin account' ) @@ -244,7 +244,7 @@ module.exports = LaunchpadController = { return next(err) } - logger.debug({ user_id: user._id }, 'making user an admin') + logger.debug({ userId: user._id }, 'making user an admin') User.updateOne( { _id: user._id }, { @@ -262,7 +262,7 @@ module.exports = LaunchpadController = { } logger.debug( - { email, user_id: user._id }, + { email, userId: user._id }, 'created first admin account' ) res.json({ redir: '/launchpad' }) diff --git a/services/web/scripts/history/debug_history.js b/services/web/scripts/history/debug_history.js index adddf85122..755716eb55 100644 --- a/services/web/scripts/history/debug_history.js +++ b/services/web/scripts/history/debug_history.js @@ -170,14 +170,14 @@ function rewindOp(content, op, log) { // is the case with this op, and shift p back appropriately to match // ShareJS if so. let { p } = op - const max_p = content.length - op.i.length - if (p > max_p) { + const maxP = content.length - op.i.length + if (p > maxP) { log.opError( 'invalid offset rewinding insert, truncating to content length', content, op ) - p = max_p + p = maxP } const textToBeRemoved = content.slice(p, p + op.i.length) if (op.i !== textToBeRemoved) { diff --git a/services/web/test/acceptance/src/ApiClsiTests.js b/services/web/test/acceptance/src/ApiClsiTests.js index 2fa3381ab9..47ba7e148b 100644 --- a/services/web/test/acceptance/src/ApiClsiTests.js +++ b/services/web/test/acceptance/src/ApiClsiTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, n/no-deprecated-api, @@ -17,7 +16,7 @@ const request = require('./helpers/request') const Settings = require('@overleaf/settings') const auth = Buffer.from('sharelatex:password').toString('base64') -const authed_request = request.defaults({ +const authedRequest = request.defaults({ headers: { Authorization: `Basic ${auth}`, }, @@ -52,7 +51,7 @@ describe('ApiClsiTests', function () { describe('valid request', function () { it('returns success and a list of output files', function (done) { - return authed_request.post( + return authedRequest.post( { uri: '/api/clsi/compile/abcd', json: this.compileSpec, @@ -108,7 +107,7 @@ describe('ApiClsiTests', function () { describe('get output', function () { describe('valid file', function () { it('returns the file', function (done) { - return authed_request.get( + return authedRequest.get( '/api/clsi/compile/abcd/build/1234/output/project.pdf', (error, response, body) => { if (error != null) { @@ -124,7 +123,7 @@ describe('ApiClsiTests', function () { describe('invalid file', function () { it('returns 404', function (done) { - return authed_request.get( + return authedRequest.get( '/api/clsi/compile/abcd/build/1234/output/project.aux', (error, response, body) => { if (error != null) { diff --git a/services/web/test/acceptance/src/ProjectFeaturesTests.js b/services/web/test/acceptance/src/ProjectFeaturesTests.js index 06ea1567ce..93f1737ea2 100644 --- a/services/web/test/acceptance/src/ProjectFeaturesTests.js +++ b/services/web/test/acceptance/src/ProjectFeaturesTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, */ @@ -17,11 +16,11 @@ const User = require('./helpers/User') const request = require('./helpers/request') const settings = require('@overleaf/settings') -const joinProject = (user_id, project_id, callback) => +const joinProject = (userId, projectId, callback) => request.post( { - url: `/project/${project_id}/join`, - qs: { user_id }, + url: `/project/${projectId}/join`, + qs: { user_id: userId }, auth: { user: settings.apis.web.user, pass: settings.apis.web.pass, @@ -42,16 +41,13 @@ describe('ProjectFeatures', function () { describe('with private project', function () { beforeEach(function (done) { - return this.owner.createProject( - 'private-project', - (error, project_id) => { - if (error != null) { - return done(error) - } - this.project_id = project_id - return done() + return this.owner.createProject('private-project', (error, projectId) => { + if (error != null) { + return done(error) } - ) + this.project_id = projectId + return done() + }) }) describe('with an upgraded account', function () { diff --git a/services/web/test/acceptance/src/RestoringFilesTest.js b/services/web/test/acceptance/src/RestoringFilesTest.js index 5a0abeba69..9b16f56c9c 100644 --- a/services/web/test/acceptance/src/RestoringFilesTest.js +++ b/services/web/test/acceptance/src/RestoringFilesTest.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-unused-vars, */ @@ -35,8 +34,8 @@ describe('RestoringFiles', function () { return this.owner.createProject( 'example-project', { template: 'example' }, - (error, project_id) => { - this.project_id = project_id + (error, projectId) => { + this.project_id = projectId if (error != null) { throw error } @@ -94,11 +93,11 @@ describe('RestoringFiles', function () { if (error != null) { throw error } - const restored_doc = _.find( + const restoredDoc = _.find( project.rootFolder[0].docs, doc => doc.name === 'main.tex' ) - expect(restored_doc._id.toString()).to.equal(this.restored_doc_id) + expect(restoredDoc._id.toString()).to.equal(this.restored_doc_id) expect(this.doc._id).to.not.equal(this.restored_doc_id) expect( MockDocstoreApi.docs[this.project_id][this.restored_doc_id].lines diff --git a/services/web/test/acceptance/src/SecurityHeadersTests.js b/services/web/test/acceptance/src/SecurityHeadersTests.js index aba148735b..9e0e1b608b 100644 --- a/services/web/test/acceptance/src/SecurityHeadersTests.js +++ b/services/web/test/acceptance/src/SecurityHeadersTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-return-assign, @@ -17,7 +16,7 @@ const async = require('async') const User = require('./helpers/User') const request = require('./helpers/request') -const assert_has_common_headers = function (response) { +const assertHasCommonHeaders = function (response) { const { headers } = response assert.include(headers, { 'x-download-options': 'noopen', @@ -31,7 +30,7 @@ const assert_has_common_headers = function (response) { assert.isUndefined(headers['cross-origin-embedder-policy']) } -const assert_has_cache_headers = function (response) { +const assertHasCacheHeaders = function (response) { assert.include(response.headers, { 'surrogate-control': 'no-store', 'cache-control': 'no-store, no-cache, must-revalidate, proxy-revalidate', @@ -40,7 +39,7 @@ const assert_has_cache_headers = function (response) { }) } -const assert_has_no_cache_headers = function (response) { +const assertHasNoCacheHeaders = function (response) { assert.doesNotHaveAnyKeys(response.headers, [ 'surrogate-control', 'cache-control', @@ -49,7 +48,7 @@ const assert_has_no_cache_headers = function (response) { ]) } -const assert_has_asset_caching_headers = function (response) { +const assertHasAssetCachingHeaders = function (response) { assert.equal(response.headers['cache-control'], 'public, max-age=31536000') } @@ -67,21 +66,21 @@ describe('SecurityHeaders', function () { it('should have all common headers', function (done) { return request.get('/', (err, res, body) => { - assert_has_common_headers(res) + assertHasCommonHeaders(res) return done() }) }) it('should not have cache headers on public pages', function (done) { return request.get('/', (err, res, body) => { - assert_has_no_cache_headers(res) + assertHasNoCacheHeaders(res) return done() }) }) it('should have caching headers on static assets', function (done) { request.get('/favicon.ico', (err, res) => { - assert_has_asset_caching_headers(res) + assertHasAssetCachingHeaders(res) done(err) }) }) @@ -94,8 +93,8 @@ describe('SecurityHeaders', function () { cb => this.user.logout(cb), ], (err, results) => { - const main_response = results[1][0] - assert_has_cache_headers(main_response) + const mainResponse = results[1][0] + assertHasCacheHeaders(mainResponse) return done() } ) @@ -108,11 +107,11 @@ describe('SecurityHeaders', function () { cb => { return this.user.createProject( 'public-project', - (error, project_id) => { + (error, projectId) => { if (error != null) { return done(error) } - this.project_id = project_id + this.project_id = projectId return this.user.makePublic(this.project_id, 'readAndWrite', cb) } ) @@ -121,7 +120,7 @@ describe('SecurityHeaders', function () { ], (err, results) => { return request.get(`/project/${this.project_id}`, (err, res, body) => { - assert_has_cache_headers(res) + assertHasCacheHeaders(res) return done() }) } @@ -137,7 +136,7 @@ describe('SecurityHeaders', function () { ], (err, results) => { const res = results[1][0] - assert_has_asset_caching_headers(res) + assertHasAssetCachingHeaders(res) done() } ) diff --git a/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js b/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js index 72aa800a73..15bd16199f 100644 --- a/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js +++ b/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js @@ -1419,7 +1419,7 @@ describe('AuthenticationController', function () { it('should log the successful login', function () { this.logger.debug .calledWith( - { email: this.user.email, user_id: this.user._id.toString() }, + { email: this.user.email, userId: this.user._id.toString() }, 'successful log in' ) .should.equal(true) diff --git a/services/web/test/unit/src/Chat/ChatControllerTests.js b/services/web/test/unit/src/Chat/ChatControllerTests.js index 697f0de44f..ca7a5e18d9 100644 --- a/services/web/test/unit/src/Chat/ChatControllerTests.js +++ b/services/web/test/unit/src/Chat/ChatControllerTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-return-assign, @@ -135,8 +134,8 @@ describe('ChatController', function () { mock: 'user_2', }, } - this.UserInfoManager.getPersonalInfo = (user_id, callback) => { - return callback(null, this.users[user_id]) + this.UserInfoManager.getPersonalInfo = (userId, callback) => { + return callback(null, this.users[userId]) } sinon.spy(this.UserInfoManager, 'getPersonalInfo') return (this.UserInfoController.formatPersonalInfo = user => ({ diff --git a/services/web/test/unit/src/Downloads/ProjectZipStreamManagerTests.js b/services/web/test/unit/src/Downloads/ProjectZipStreamManagerTests.js index c778c08099..ed5c21979a 100644 --- a/services/web/test/unit/src/Downloads/ProjectZipStreamManagerTests.js +++ b/services/web/test/unit/src/Downloads/ProjectZipStreamManagerTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-return-assign, no-unused-vars, @@ -55,19 +54,19 @@ describe('ProjectZipStreamManager', function () { } this.ProjectZipStreamManager.createZipStreamForProject = ( - project_id, + projectId, callback ) => { - callback(null, this.zip_streams[project_id]) + callback(null, this.zip_streams[projectId]) setTimeout(() => { - return this.zip_streams[project_id].emit('end') + return this.zip_streams[projectId].emit('end') }) return 0 } sinon.spy(this.ProjectZipStreamManager, 'createZipStreamForProject') - this.ProjectGetter.getProject = (project_id, fields, callback) => { - return callback(null, { name: this.project_names[project_id] }) + this.ProjectGetter.getProject = (projectId, fields, callback) => { + return callback(null, { name: this.project_names[projectId] }) } sinon.spy(this.ProjectGetter, 'getProject') @@ -95,26 +94,26 @@ describe('ProjectZipStreamManager', function () { }) it('should get a zip stream for all of the projects', function () { - return Array.from(this.project_ids).map(project_id => + return Array.from(this.project_ids).map(projectId => this.ProjectZipStreamManager.createZipStreamForProject - .calledWith(project_id) + .calledWith(projectId) .should.equal(true) ) }) it('should get the names of each project', function () { - return Array.from(this.project_ids).map(project_id => + return Array.from(this.project_ids).map(projectId => this.ProjectGetter.getProject - .calledWith(project_id, { name: true }) + .calledWith(projectId, { name: true }) .should.equal(true) ) }) it('should add all of the projects to the zip', function () { - return Array.from(this.project_ids).map(project_id => + return Array.from(this.project_ids).map(projectId => this.archive.append - .calledWith(this.zip_streams[project_id], { - name: this.project_names[project_id] + '.zip', + .calledWith(this.zip_streams[projectId], { + name: this.project_names[projectId] + '.zip', }) .should.equal(true) ) @@ -132,18 +131,18 @@ describe('ProjectZipStreamManager', function () { } this.ProjectZipStreamManager.createZipStreamForProject = ( - project_id, + projectId, callback ) => { - callback(null, this.zip_streams[project_id]) + callback(null, this.zip_streams[projectId]) setTimeout(() => { - this.zip_streams[project_id].emit('end') + this.zip_streams[projectId].emit('end') }) } sinon.spy(this.ProjectZipStreamManager, 'createZipStreamForProject') - this.ProjectGetter.getProject = (project_id, fields, callback) => { - const name = this.project_names[project_id] + this.ProjectGetter.getProject = (projectId, fields, callback) => { + const name = this.project_names[projectId] callback(null, name ? { name } : undefined) } sinon.spy(this.ProjectGetter, 'getProject') @@ -170,9 +169,9 @@ describe('ProjectZipStreamManager', function () { }) it('should get the names of each project', function () { - this.project_ids.map(project_id => + this.project_ids.map(projectId => this.ProjectGetter.getProject - .calledWith(project_id, { name: true }) + .calledWith(projectId, { name: true }) .should.equal(true) ) }) @@ -379,10 +378,10 @@ describe('ProjectZipStreamManager', function () { this.ProjectEntityHandler.getAllFiles = sinon .stub() .callsArgWith(1, null, this.files) - this.FileStoreHandler.getFileStream = (project_id, file_id, ...rest) => { + this.FileStoreHandler.getFileStream = (projectId, fileId, ...rest) => { const obj = rest[0], callback = rest[1] - return callback(null, this.streams[file_id]) + return callback(null, this.streams[fileId]) } sinon.spy(this.FileStoreHandler, 'getFileStream') this.ProjectZipStreamManager.addAllFilesToArchive( diff --git a/services/web/test/unit/src/Exports/ExportsControllerTests.js b/services/web/test/unit/src/Exports/ExportsControllerTests.js index 356eacf25e..0c82981ab0 100644 --- a/services/web/test/unit/src/Exports/ExportsControllerTests.js +++ b/services/web/test/unit/src/Exports/ExportsControllerTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-return-assign, no-unused-vars, @@ -22,23 +21,23 @@ const modulePath = require('path').join( ) describe('ExportsController', function () { - const project_id = '123njdskj9jlk' - const user_id = '123nd3ijdks' - const brand_variation_id = 22 + const projectId = '123njdskj9jlk' + const userId = '123nd3ijdks' + const brandVariationId = 22 const firstName = 'first' const lastName = 'last' const title = 'title' const description = 'description' const author = 'author' const license = 'other' - const show_source = true + const showSource = true beforeEach(function () { this.handler = { getUserNotifications: sinon.stub().callsArgWith(1) } this.req = { params: { - project_id, - brand_variation_id, + project_id: projectId, + brand_variation_id: brandVariationId, }, body: { firstName, @@ -46,7 +45,7 @@ describe('ExportsController', function () { }, session: { user: { - _id: user_id, + _id: userId, }, }, i18n: { @@ -77,9 +76,9 @@ describe('ExportsController', function () { .stub() .yields(null, { iAmAnExport: true, v1_id: 897 }) const expected = { - project_id, - user_id, - brand_variation_id, + project_id: projectId, + user_id: userId, + brand_variation_id: brandVariationId, first_name: firstName, last_name: lastName, } @@ -101,9 +100,9 @@ describe('ExportsController', function () { message: 'RESUBMISSION', }) const expected = { - project_id, - user_id, - brand_variation_id, + project_id: projectId, + user_id: userId, + brand_variation_id: brandVariationId, first_name: firstName, last_name: lastName, } @@ -134,16 +133,16 @@ describe('ExportsController', function () { .stub() .yields(null, { iAmAnExport: true, v1_id: 897 }) const expected = { - project_id, - user_id, - brand_variation_id, + project_id: projectId, + user_id: userId, + brand_variation_id: brandVariationId, first_name: firstName, last_name: lastName, title, description, author, license, - show_source, + show_source: showSource, } return this.controller.exportProject(this.req, { json: body => { @@ -184,7 +183,7 @@ describe('ExportsController', function () { }` ) - this.req.params = { project_id, export_id: 897 } + this.req.params = { project_id: projectId, export_id: 897 } return this.controller.exportStatus(this.req, { json: body => { expect(body).to.deep.equal({ diff --git a/services/web/test/unit/src/Exports/ExportsHandlerTests.js b/services/web/test/unit/src/Exports/ExportsHandlerTests.js index 6e81a21a04..5708f55e7a 100644 --- a/services/web/test/unit/src/Exports/ExportsHandlerTests.js +++ b/services/web/test/unit/src/Exports/ExportsHandlerTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-return-assign, no-unused-vars, @@ -73,8 +72,8 @@ describe('ExportsHandler', function () { beforeEach(function (done) { return this.ExportsHandler.exportProject( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) @@ -106,8 +105,8 @@ describe('ExportsHandler', function () { .yields(new Error('cannot export project without root doc')) return this.ExportsHandler.exportProject( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) @@ -126,8 +125,8 @@ describe('ExportsHandler', function () { .yields(null, { forwardResponse: this.error_json }) return this.ExportsHandler.exportProject( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) @@ -188,8 +187,8 @@ describe('ExportsHandler', function () { beforeEach(function (done) { return this.ExportsHandler._buildExport( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) @@ -206,7 +205,7 @@ describe('ExportsHandler', function () { }) it('should return export data', function () { - const expected_export_data = { + const expectedExportData = { project: { id: this.project_id, rootDocPath: this.rootDocPath, @@ -239,7 +238,7 @@ describe('ExportsHandler', function () { }, } return this.callback - .calledWith(null, expected_export_data) + .calledWith(null, expectedExportData) .should.equal(true) }) }) @@ -252,15 +251,15 @@ describe('ExportsHandler', function () { this.export_params.last_name = this.custom_last_name return this.ExportsHandler._buildExport( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) }) it('should send the data from the user input', function () { - const expected_export_data = { + const expectedExportData = { project: { id: this.project_id, rootDocPath: this.rootDocPath, @@ -293,7 +292,7 @@ describe('ExportsHandler', function () { }, } return this.callback - .calledWith(null, expected_export_data) + .calledWith(null, expectedExportData) .should.equal(true) }) }) @@ -305,8 +304,8 @@ describe('ExportsHandler', function () { .yields(new Error('project not found')) return this.ExportsHandler._buildExport( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) @@ -326,8 +325,8 @@ describe('ExportsHandler', function () { .yields(null, [null, { fileSystem: 'other.tex' }]) return this.ExportsHandler._buildExport( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) @@ -340,7 +339,7 @@ describe('ExportsHandler', function () { }) it('should return export data', function () { - const expected_export_data = { + const expectedExportData = { project: { id: this.project_id, rootDocPath: 'other.tex', @@ -373,7 +372,7 @@ describe('ExportsHandler', function () { }, } return this.callback - .calledWith(null, expected_export_data) + .calledWith(null, expectedExportData) .should.equal(true) }) }) @@ -389,8 +388,8 @@ describe('ExportsHandler', function () { .yields(null, [null, { fileSystem: 'other.tex' }]) return this.ExportsHandler._buildExport( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) @@ -403,7 +402,7 @@ describe('ExportsHandler', function () { }) it('should return export data', function () { - const expected_export_data = { + const expectedExportData = { project: { id: this.project_id, rootDocPath: 'other.tex', @@ -436,7 +435,7 @@ describe('ExportsHandler', function () { }, } return this.callback - .calledWith(null, expected_export_data) + .calledWith(null, expectedExportData) .should.equal(true) }) }) @@ -448,8 +447,8 @@ describe('ExportsHandler', function () { .yields(null, [null, null]) return this.ExportsHandler._buildExport( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) @@ -468,8 +467,8 @@ describe('ExportsHandler', function () { .yields(new Error('user not found')) return this.ExportsHandler._buildExport( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) @@ -487,8 +486,8 @@ describe('ExportsHandler', function () { .yields(new Error('project history call failed')) return this.ExportsHandler._buildExport( this.export_params, - (error, export_data) => { - this.callback(error, export_data) + (error, exportData) => { + this.callback(error, exportData) return done() } ) @@ -523,8 +522,8 @@ describe('ExportsHandler', function () { this.stubRequest.post = this.stubPost return this.ExportsHandler._requestExport( this.export_data, - (error, export_v1_id) => { - this.callback(error, export_v1_id) + (error, exportV1Id) => { + this.callback(error, exportV1Id) return done() } ) @@ -556,8 +555,8 @@ describe('ExportsHandler', function () { .yields(new Error('export request failed')) return this.ExportsHandler._requestExport( this.export_data, - (error, export_v1_id) => { - this.callback(error, export_v1_id) + (error, exportV1Id) => { + this.callback(error, exportV1Id) return done() } ) @@ -577,8 +576,8 @@ describe('ExportsHandler', function () { .yields(null, { statusCode: this.error_code }, this.error_json) return this.ExportsHandler._requestExport( this.export_data, - (error, export_v1_id) => { - this.callback(error, export_v1_id) + (error, exportV1Id) => { + this.callback(error, exportV1Id) return done() } ) diff --git a/services/web/test/unit/src/Notifications/NotificationsHandlerTests.js b/services/web/test/unit/src/Notifications/NotificationsHandlerTests.js index 3fabbf08c1..0be96e3d3d 100644 --- a/services/web/test/unit/src/Notifications/NotificationsHandlerTests.js +++ b/services/web/test/unit/src/Notifications/NotificationsHandlerTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-return-assign, @@ -22,8 +21,8 @@ const modulePath = require('path').join( const _ = require('underscore') describe('NotificationsHandler', function () { - const user_id = '123nd3ijdks' - const notification_id = '123njdskj9jlk' + const userId = '123nd3ijdks' + const notificationId = '123njdskj9jlk' const notificationUrl = 'notification.sharelatex.testing' beforeEach(function () { @@ -40,7 +39,7 @@ describe('NotificationsHandler', function () { describe('getUserNotifications', function () { it('should get unread notifications', function (done) { - const stubbedNotifications = [{ _id: notification_id, user_id }] + const stubbedNotifications = [{ _id: notificationId, user_id: userId }] this.request.callsArgWith( 1, null, @@ -48,11 +47,11 @@ describe('NotificationsHandler', function () { stubbedNotifications ) return this.handler.getUserNotifications( - user_id, + userId, (err, unreadNotifications) => { stubbedNotifications.should.deep.equal(unreadNotifications) const getOpts = { - uri: `${notificationUrl}/user/${user_id}`, + uri: `${notificationUrl}/user/${userId}`, json: true, timeout: 1000, method: 'GET', @@ -66,7 +65,7 @@ describe('NotificationsHandler', function () { it('should return empty arrays if there are no notifications', function () { this.request.callsArgWith(1, null, { statusCode: 200 }, null) return this.handler.getUserNotifications( - user_id, + userId, (err, unreadNotifications) => { return unreadNotifications.length.should.equal(0) } @@ -80,9 +79,9 @@ describe('NotificationsHandler', function () { }) it('should send a delete request when a delete has been received to mark a notification', function (done) { - return this.handler.markAsReadWithKey(user_id, this.key, () => { + return this.handler.markAsReadWithKey(userId, this.key, () => { const opts = { - uri: `${notificationUrl}/user/${user_id}`, + uri: `${notificationUrl}/user/${userId}`, json: { key: this.key, }, @@ -105,14 +104,14 @@ describe('NotificationsHandler', function () { it('should post the message over', function (done) { return this.handler.createNotification( - user_id, + userId, this.key, this.templateKey, this.messageOpts, this.expiry, () => { const args = this.request.args[0][0] - args.uri.should.equal(`${notificationUrl}/user/${user_id}`) + args.uri.should.equal(`${notificationUrl}/user/${userId}`) args.timeout.should.equal(1000) const expectedJson = { key: this.key, @@ -136,14 +135,14 @@ describe('NotificationsHandler', function () { it('should post the message over with expiry field', function (done) { return this.handler.createNotification( - user_id, + userId, this.key, this.templateKey, this.messageOpts, this.expiry, () => { const args = this.request.args[0][0] - args.uri.should.equal(`${notificationUrl}/user/${user_id}`) + args.uri.should.equal(`${notificationUrl}/user/${userId}`) args.timeout.should.equal(1000) const expectedJson = { key: this.key, diff --git a/services/web/test/unit/src/Project/ProjectHistoryHandlerTests.js b/services/web/test/unit/src/Project/ProjectHistoryHandlerTests.js index 148c6e1272..d6b0a24785 100644 --- a/services/web/test/unit/src/Project/ProjectHistoryHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectHistoryHandlerTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, max-len, no-return-assign, no-unused-vars, @@ -18,7 +17,7 @@ const modulePath = '../../../../app/src/Features/Project/ProjectHistoryHandler' const SandboxedModule = require('sandboxed-module') describe('ProjectHistoryHandler', function () { - const project_id = '4eecb1c1bffa66588e0000a1' + const projectId = '4eecb1c1bffa66588e0000a1' const userId = 1234 beforeEach(function () { @@ -30,7 +29,7 @@ describe('ProjectHistoryHandler', function () { } constructor(options) { - this._id = project_id + this._id = projectId this.name = 'project_name_here' this.rev = 0 } @@ -71,20 +70,20 @@ describe('ProjectHistoryHandler', function () { beforeEach(function () { this.ProjectDetailsHandler.getDetails = sinon .stub() - .withArgs(project_id) + .withArgs(projectId) .callsArgWith(1, null, this.project) this.ProjectModel.updateOne = sinon .stub() .callsArgWith(2, null, { matchedCount: 1 }) return this.ProjectHistoryHandler.ensureHistoryExistsForProject( - project_id, + projectId, this.callback ) }) it('should get any existing history id for the project', function () { return this.ProjectDetailsHandler.getDetails - .calledWith(project_id) + .calledWith(projectId) .should.equal(true) }) @@ -95,7 +94,7 @@ describe('ProjectHistoryHandler', function () { it('should set the new history id on the project', function () { return this.ProjectModel.updateOne .calledWith( - { _id: project_id, 'overleaf.history.id': { $exists: false } }, + { _id: projectId, 'overleaf.history.id': { $exists: false } }, { 'overleaf.history.id': this.historyId } ) .should.equal(true) @@ -103,13 +102,13 @@ describe('ProjectHistoryHandler', function () { it('should resync the project history', function () { return this.ProjectEntityUpdateHandler.resyncProjectHistory - .calledWith(project_id) + .calledWith(projectId) .should.equal(true) }) it('should flush the project history', function () { return this.HistoryManager.flushProject - .calledWith(project_id) + .calledWith(projectId) .should.equal(true) }) @@ -123,18 +122,18 @@ describe('ProjectHistoryHandler', function () { this.project.overleaf = { history: { id: 1234 } } this.ProjectDetailsHandler.getDetails = sinon .stub() - .withArgs(project_id) + .withArgs(projectId) .callsArgWith(1, null, this.project) this.ProjectModel.updateOne = sinon.stub() return this.ProjectHistoryHandler.ensureHistoryExistsForProject( - project_id, + projectId, this.callback ) }) it('should get any existing history id for the project', function () { return this.ProjectDetailsHandler.getDetails - .calledWith(project_id) + .calledWith(projectId) .should.equal(true) }) diff --git a/services/web/test/unit/src/Project/ProjectOptionsHandlerTests.js b/services/web/test/unit/src/Project/ProjectOptionsHandlerTests.js index 2ebe618d8e..c3f2fcfae6 100644 --- a/services/web/test/unit/src/Project/ProjectOptionsHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectOptionsHandlerTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-return-assign, @@ -20,7 +19,7 @@ const modulePath = const SandboxedModule = require('sandboxed-module') describe('ProjectOptionsHandler', function () { - const project_id = '4eecaffcbffa66588e000008' + const projectId = '4eecaffcbffa66588e000008' beforeEach(function () { let Project @@ -49,16 +48,16 @@ describe('ProjectOptionsHandler', function () { describe('Setting the compiler', function () { it('should perform and update on mongo', function (done) { - this.handler.setCompiler(project_id, 'xeLaTeX', err => { + this.handler.setCompiler(projectId, 'xeLaTeX', err => { const args = this.projectModel.updateOne.args[0] - args[0]._id.should.equal(project_id) + args[0]._id.should.equal(projectId) args[1].compiler.should.equal('xelatex') done() }) }) it('should not perform and update on mongo if it is not a recognised compiler', function (done) { - this.handler.setCompiler(project_id, 'something', err => { + this.handler.setCompiler(projectId, 'something', err => { this.projectModel.updateOne.called.should.equal(false) done() }) @@ -66,7 +65,7 @@ describe('ProjectOptionsHandler', function () { describe('when called without arg', function () { it('should callback with null', function (done) { - this.handler.setCompiler(project_id, null, err => { + this.handler.setCompiler(projectId, null, err => { expect(err).to.be.undefined this.projectModel.updateOne.callCount.should.equal(0) done() @@ -80,7 +79,7 @@ describe('ProjectOptionsHandler', function () { }) it('should callback with error', function (done) { - this.handler.setCompiler(project_id, 'xeLaTeX', err => { + this.handler.setCompiler(projectId, 'xeLaTeX', err => { err.should.equal('error') done() }) @@ -90,16 +89,16 @@ describe('ProjectOptionsHandler', function () { describe('Setting the imageName', function () { it('should perform and update on mongo', function (done) { - this.handler.setImageName(project_id, 'texlive-1234.5', err => { + this.handler.setImageName(projectId, 'texlive-1234.5', err => { const args = this.projectModel.updateOne.args[0] - args[0]._id.should.equal(project_id) + args[0]._id.should.equal(projectId) args[1].imageName.should.equal('docker-repo/subdir/texlive-1234.5') done() }) }) it('should not perform and update on mongo if it is not a reconised compiler', function (done) { - this.handler.setImageName(project_id, 'something', err => { + this.handler.setImageName(projectId, 'something', err => { this.projectModel.updateOne.called.should.equal(false) done() }) @@ -107,7 +106,7 @@ describe('ProjectOptionsHandler', function () { describe('when called without arg', function () { it('should callback with null', function (done) { - this.handler.setImageName(project_id, null, err => { + this.handler.setImageName(projectId, null, err => { expect(err).to.be.undefined this.projectModel.updateOne.callCount.should.equal(0) done() @@ -121,7 +120,7 @@ describe('ProjectOptionsHandler', function () { }) it('should callback with error', function (done) { - this.handler.setImageName(project_id, 'texlive-1234.5', err => { + this.handler.setImageName(projectId, 'texlive-1234.5', err => { err.should.equal('error') done() }) @@ -131,23 +130,23 @@ describe('ProjectOptionsHandler', function () { describe('setting the spellCheckLanguage', function () { it('should perform and update on mongo', function (done) { - this.handler.setSpellCheckLanguage(project_id, 'fr', err => { + this.handler.setSpellCheckLanguage(projectId, 'fr', err => { const args = this.projectModel.updateOne.args[0] - args[0]._id.should.equal(project_id) + args[0]._id.should.equal(projectId) args[1].spellCheckLanguage.should.equal('fr') done() }) }) it('should not perform and update on mongo if it is not a reconised compiler', function (done) { - this.handler.setSpellCheckLanguage(project_id, 'no a lang', err => { + this.handler.setSpellCheckLanguage(projectId, 'no a lang', err => { this.projectModel.updateOne.called.should.equal(false) done() }) }) it('should perform and update on mongo if the language is blank (means turn it off)', function (done) { - this.handler.setSpellCheckLanguage(project_id, '', err => { + this.handler.setSpellCheckLanguage(projectId, '', err => { this.projectModel.updateOne.called.should.equal(true) done() }) @@ -159,7 +158,7 @@ describe('ProjectOptionsHandler', function () { }) it('should callback with error', function (done) { - this.handler.setSpellCheckLanguage(project_id, 'fr', err => { + this.handler.setSpellCheckLanguage(projectId, 'fr', err => { err.should.equal('error') done() }) @@ -169,23 +168,23 @@ describe('ProjectOptionsHandler', function () { describe('setting the brandVariationId', function () { it('should perform and update on mongo', function (done) { - this.handler.setBrandVariationId(project_id, '123', err => { + this.handler.setBrandVariationId(projectId, '123', err => { const args = this.projectModel.updateOne.args[0] - args[0]._id.should.equal(project_id) + args[0]._id.should.equal(projectId) args[1].brandVariationId.should.equal('123') done() }) }) it('should not perform and update on mongo if there is no brand variation', function (done) { - this.handler.setBrandVariationId(project_id, null, err => { + this.handler.setBrandVariationId(projectId, null, err => { this.projectModel.updateOne.called.should.equal(false) done() }) }) it('should not perform and update on mongo if brand variation is an empty string', function (done) { - this.handler.setBrandVariationId(project_id, '', err => { + this.handler.setBrandVariationId(projectId, '', err => { this.projectModel.updateOne.called.should.equal(false) done() }) @@ -197,7 +196,7 @@ describe('ProjectOptionsHandler', function () { }) it('should callback with error', function (done) { - this.handler.setBrandVariationId(project_id, '123', err => { + this.handler.setBrandVariationId(projectId, '123', err => { err.should.equal('error') done() }) @@ -207,9 +206,9 @@ describe('ProjectOptionsHandler', function () { describe('unsetting the brandVariationId', function () { it('should perform and update on mongo', function (done) { - this.handler.unsetBrandVariationId(project_id, err => { + this.handler.unsetBrandVariationId(projectId, err => { const args = this.projectModel.updateOne.args[0] - args[0]._id.should.equal(project_id) + args[0]._id.should.equal(projectId) expect(args[1]).to.deep.equal({ $unset: { brandVariationId: 1 } }) done() }) @@ -221,7 +220,7 @@ describe('ProjectOptionsHandler', function () { }) it('should callback with error', function (done) { - this.handler.unsetBrandVariationId(project_id, err => { + this.handler.unsetBrandVariationId(projectId, err => { err.should.equal('error') done() }) diff --git a/services/web/test/unit/src/Project/ProjectUpdateHandlerTests.js b/services/web/test/unit/src/Project/ProjectUpdateHandlerTests.js index 5dee084886..0cc6354694 100644 --- a/services/web/test/unit/src/Project/ProjectUpdateHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectUpdateHandlerTests.js @@ -1,5 +1,4 @@ /* eslint-disable - camelcase, n/handle-callback-err, max-len, no-return-assign, @@ -83,10 +82,10 @@ describe('ProjectUpdateHandler', function () { describe('markAsOpened', function () { it('should send an update to mongo', function (done) { - const project_id = 'project_id' - return this.handler.markAsOpened(project_id, err => { + const projectId = 'project_id' + return this.handler.markAsOpened(projectId, err => { const args = this.ProjectModel.updateOne.args[0] - args[0]._id.should.equal(project_id) + args[0]._id.should.equal(projectId) const date = args[1].lastOpened + '' const now = Date.now() + '' date.substring(0, 5).should.equal(now.substring(0, 5)) @@ -97,10 +96,10 @@ describe('ProjectUpdateHandler', function () { describe('markAsInactive', function () { it('should send an update to mongo', function (done) { - const project_id = 'project_id' - return this.handler.markAsInactive(project_id, err => { + const projectId = 'project_id' + return this.handler.markAsInactive(projectId, err => { const args = this.ProjectModel.updateOne.args[0] - args[0]._id.should.equal(project_id) + args[0]._id.should.equal(projectId) args[1].active.should.equal(false) return done() }) @@ -109,10 +108,10 @@ describe('ProjectUpdateHandler', function () { describe('markAsActive', function () { it('should send an update to mongo', function (done) { - const project_id = 'project_id' - return this.handler.markAsActive(project_id, err => { + const projectId = 'project_id' + return this.handler.markAsActive(projectId, err => { const args = this.ProjectModel.updateOne.args[0] - args[0]._id.should.equal(project_id) + args[0]._id.should.equal(projectId) args[1].active.should.equal(true) return done() })