From a397154e182c7f2f583511dfc5acb0e8909c1e95 Mon Sep 17 00:00:00 2001 From: decaffeinate Date: Tue, 23 Jun 2020 18:29:38 +0100 Subject: [PATCH] decaffeinate: Run post-processing cleanups on AuthorizationManager.coffee and 18 other files --- .../app/coffee/AuthorizationManager.js | 8 +++- .../real-time/app/coffee/ChannelManager.js | 5 ++ .../app/coffee/ConnectedUsersManager.js | 6 +++ .../app/coffee/DocumentUpdaterController.js | 8 +++- .../app/coffee/DocumentUpdaterManager.js | 11 ++++- services/real-time/app/coffee/DrainManager.js | 7 ++- services/real-time/app/coffee/Errors.js | 6 +++ services/real-time/app/coffee/EventLogger.js | 7 ++- .../app/coffee/HealthCheckManager.js | 12 ++++- .../real-time/app/coffee/HttpApiController.js | 8 +++- .../real-time/app/coffee/HttpController.js | 8 +++- .../app/coffee/RedisClientManager.js | 7 ++- services/real-time/app/coffee/RoomManager.js | 10 +++- services/real-time/app/coffee/Router.js | 9 +++- .../real-time/app/coffee/SafeJsonParse.js | 5 ++ .../real-time/app/coffee/SessionSockets.js | 2 + .../real-time/app/coffee/WebApiManager.js | 9 +++- .../app/coffee/WebsocketController.js | 46 ++++++++++--------- .../app/coffee/WebsocketLoadBalancer.js | 9 +++- 19 files changed, 145 insertions(+), 38 deletions(-) diff --git a/services/real-time/app/coffee/AuthorizationManager.js b/services/real-time/app/coffee/AuthorizationManager.js index 0ce4c313e2..41caee9ef2 100644 --- a/services/real-time/app/coffee/AuthorizationManager.js +++ b/services/real-time/app/coffee/AuthorizationManager.js @@ -1,3 +1,9 @@ +/* eslint-disable + camelcase, + handle-callback-err, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from @@ -19,7 +25,7 @@ module.exports = (AuthorizationManager = { _assertClientHasPrivilegeLevel(client, allowedLevels, callback) { if (callback == null) { callback = function(error) {}; } - if (Array.from(allowedLevels).includes(client.ol_context["privilege_level"])) { + if (Array.from(allowedLevels).includes(client.ol_context.privilege_level)) { return callback(null); } else { return callback(new Error("not authorized")); diff --git a/services/real-time/app/coffee/ChannelManager.js b/services/real-time/app/coffee/ChannelManager.js index eb73802a07..60e7c5c635 100644 --- a/services/real-time/app/coffee/ChannelManager.js +++ b/services/real-time/app/coffee/ChannelManager.js @@ -1,3 +1,8 @@ +/* eslint-disable + no-unused-vars, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns diff --git a/services/real-time/app/coffee/ConnectedUsersManager.js b/services/real-time/app/coffee/ConnectedUsersManager.js index bfdcf608a0..b2a0fc2eee 100644 --- a/services/real-time/app/coffee/ConnectedUsersManager.js +++ b/services/real-time/app/coffee/ConnectedUsersManager.js @@ -1,3 +1,9 @@ +/* eslint-disable + camelcase, + handle-callback-err, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns diff --git a/services/real-time/app/coffee/DocumentUpdaterController.js b/services/real-time/app/coffee/DocumentUpdaterController.js index 85078219b6..cbf5c600fd 100644 --- a/services/real-time/app/coffee/DocumentUpdaterController.js +++ b/services/real-time/app/coffee/DocumentUpdaterController.js @@ -1,3 +1,9 @@ +/* eslint-disable + camelcase, + no-unused-vars, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from @@ -123,7 +129,7 @@ module.exports = (DocumentUpdaterController = { _processErrorFromDocumentUpdater(io, doc_id, error, message) { return (() => { const result = []; - for (let client of Array.from(io.sockets.clients(doc_id))) { + for (const client of Array.from(io.sockets.clients(doc_id))) { logger.warn({err: error, doc_id, client_id: client.id}, "error from document updater, disconnecting client"); client.emit("otUpdateError", error, message); result.push(client.disconnect()); diff --git a/services/real-time/app/coffee/DocumentUpdaterManager.js b/services/real-time/app/coffee/DocumentUpdaterManager.js index 4b07b8f381..dc5865db62 100644 --- a/services/real-time/app/coffee/DocumentUpdaterManager.js +++ b/services/real-time/app/coffee/DocumentUpdaterManager.js @@ -1,3 +1,10 @@ +/* eslint-disable + camelcase, + handle-callback-err, + no-unused-vars, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns @@ -26,7 +33,7 @@ module.exports = (DocumentUpdaterManager = { logger.error({err, url, project_id, doc_id}, "error getting doc from doc updater"); return callback(err); } - if (200 <= res.statusCode && res.statusCode < 300) { + if (res.statusCode >= 200 && res.statusCode < 300) { logger.log({project_id, doc_id}, "got doc from document document updater"); try { body = JSON.parse(body); @@ -61,7 +68,7 @@ module.exports = (DocumentUpdaterManager = { if (err != null) { logger.error({err, project_id}, "error deleting project from document updater"); return callback(err); - } else if (200 <= res.statusCode && res.statusCode < 300) { + } else if (res.statusCode >= 200 && res.statusCode < 300) { logger.log({project_id}, "deleted project from document updater"); return callback(null); } else { diff --git a/services/real-time/app/coffee/DrainManager.js b/services/real-time/app/coffee/DrainManager.js index 2f4067cc3c..466c80fd0c 100644 --- a/services/real-time/app/coffee/DrainManager.js +++ b/services/real-time/app/coffee/DrainManager.js @@ -1,3 +1,8 @@ +/* eslint-disable + no-return-assign, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from @@ -38,7 +43,7 @@ module.exports = (DrainManager = { RECONNECTED_CLIENTS: {}, reconnectNClients(io, N) { let drainedCount = 0; - for (let client of Array.from(io.sockets.clients())) { + for (const client of Array.from(io.sockets.clients())) { if (!this.RECONNECTED_CLIENTS[client.id]) { this.RECONNECTED_CLIENTS[client.id] = true; logger.log({client_id: client.id}, "Asking client to reconnect gracefully"); diff --git a/services/real-time/app/coffee/Errors.js b/services/real-time/app/coffee/Errors.js index 2ae4fbd6ab..04437742fb 100644 --- a/services/real-time/app/coffee/Errors.js +++ b/services/real-time/app/coffee/Errors.js @@ -1,3 +1,9 @@ +/* eslint-disable + no-proto, + no-unused-vars, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. let Errors; var CodedError = function(message, code) { const error = new Error(message); diff --git a/services/real-time/app/coffee/EventLogger.js b/services/real-time/app/coffee/EventLogger.js index bc01011687..8a700326b5 100644 --- a/services/real-time/app/coffee/EventLogger.js +++ b/services/real-time/app/coffee/EventLogger.js @@ -1,3 +1,8 @@ +/* eslint-disable + camelcase, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns @@ -73,7 +78,7 @@ module.exports = (EventLogger = { _cleanEventStream(now) { return (() => { const result = []; - for (let key in EVENT_LOG_TIMESTAMP) { + for (const key in EVENT_LOG_TIMESTAMP) { const timestamp = EVENT_LOG_TIMESTAMP[key]; if ((now - timestamp) > EventLogger.MAX_STALE_TIME_IN_MS) { delete EVENT_LOG_COUNTER[key]; diff --git a/services/real-time/app/coffee/HealthCheckManager.js b/services/real-time/app/coffee/HealthCheckManager.js index 47da253993..f8a9aa672e 100644 --- a/services/real-time/app/coffee/HealthCheckManager.js +++ b/services/real-time/app/coffee/HealthCheckManager.js @@ -1,3 +1,9 @@ +/* eslint-disable + no-return-assign, + no-unused-vars, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns @@ -36,6 +42,7 @@ module.exports = (HealthCheckManager = class HealthCheckManager { // keep a record of these objects to dispatch on CHANNEL_MANAGER[this.channel] = this; } + processEvent(id) { // if this is our event record it if (id === this.id) { @@ -46,6 +53,7 @@ module.exports = (HealthCheckManager = class HealthCheckManager { return this.timer = null; // only time the latency of the first event } } + setStatus() { // if we saw the event anything other than a single time that is an error if (this.count !== 1) { @@ -60,13 +68,15 @@ module.exports = (HealthCheckManager = class HealthCheckManager { // dispatch event to manager for channel return (CHANNEL_MANAGER[channel] != null ? CHANNEL_MANAGER[channel].processEvent(id) : undefined); } + static status() { // return status of all channels for logging return CHANNEL_ERROR; } + static isFailing() { // check if any channel status is bad - for (let channel in CHANNEL_ERROR) { + for (const channel in CHANNEL_ERROR) { const error = CHANNEL_ERROR[channel]; if (error === true) { return true; } } diff --git a/services/real-time/app/coffee/HttpApiController.js b/services/real-time/app/coffee/HttpApiController.js index 21a9f15628..88bbc1a5e3 100644 --- a/services/real-time/app/coffee/HttpApiController.js +++ b/services/real-time/app/coffee/HttpApiController.js @@ -1,3 +1,9 @@ +/* eslint-disable + camelcase, + no-unused-vars, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from @@ -13,7 +19,7 @@ module.exports = (HttpApiController = { sendMessage(req, res, next) { logger.log({message: req.params.message}, "sending message"); if (Array.isArray(req.body)) { - for (let payload of Array.from(req.body)) { + for (const payload of Array.from(req.body)) { WebsocketLoadBalancer.emitToRoom(req.params.project_id, req.params.message, payload); } } else { diff --git a/services/real-time/app/coffee/HttpController.js b/services/real-time/app/coffee/HttpController.js index aa17c6f6d8..4d33af44b3 100644 --- a/services/real-time/app/coffee/HttpController.js +++ b/services/real-time/app/coffee/HttpController.js @@ -1,3 +1,9 @@ +/* eslint-disable + camelcase, + handle-callback-err, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns @@ -19,7 +25,7 @@ module.exports = (HttpController = { const {project_id, user_id, first_name, last_name, email, connected_time} = ioClient.ol_context; const client = {client_id, project_id, user_id, first_name, last_name, email, connected_time}; client.rooms = []; - for (let name in ioClient.manager.roomClients[client_id]) { + for (const name in ioClient.manager.roomClients[client_id]) { const joined = ioClient.manager.roomClients[client_id][name]; if (joined && (name !== "")) { client.rooms.push(name.replace(/^\//, "")); // Remove leading / diff --git a/services/real-time/app/coffee/RedisClientManager.js b/services/real-time/app/coffee/RedisClientManager.js index 7bd33ca914..3da2136b46 100644 --- a/services/real-time/app/coffee/RedisClientManager.js +++ b/services/real-time/app/coffee/RedisClientManager.js @@ -1,3 +1,8 @@ +/* eslint-disable + no-unused-vars, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from @@ -14,7 +19,7 @@ module.exports = (RedisClientManager = { // create a dynamic list of redis clients, excluding any configurations which are not defined const clientList = (() => { const result = []; - for (let x of Array.from(configs)) { + for (const x of Array.from(configs)) { if (x != null) { const redisType = (x.cluster != null) ? "cluster" diff --git a/services/real-time/app/coffee/RoomManager.js b/services/real-time/app/coffee/RoomManager.js index c7047e90c0..c75cc68626 100644 --- a/services/real-time/app/coffee/RoomManager.js +++ b/services/real-time/app/coffee/RoomManager.js @@ -1,3 +1,9 @@ +/* eslint-disable + camelcase, + no-unused-vars, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from @@ -51,7 +57,7 @@ module.exports = (RoomManager = { logger.log({client: client.id, roomsToLeave}, "client leaving project"); return (() => { const result = []; - for (let id of Array.from(roomsToLeave)) { + for (const id of Array.from(roomsToLeave)) { const entity = IdMap.get(id); result.push(this.leaveEntity(client, entity, id)); } @@ -131,7 +137,7 @@ module.exports = (RoomManager = { _roomsClientIsIn(client) { const roomList = (() => { const result = []; - for (let fullRoomPath in (client.manager.roomClients != null ? client.manager.roomClients[client.id] : undefined)) { + for (const fullRoomPath in (client.manager.roomClients != null ? client.manager.roomClients[client.id] : undefined)) { // strip socket.io prefix from room to get original id if (fullRoomPath !== '') { const [prefix, room] = Array.from(fullRoomPath.split('/', 2)); diff --git a/services/real-time/app/coffee/Router.js b/services/real-time/app/coffee/Router.js index c7ea84192b..f475596036 100644 --- a/services/real-time/app/coffee/Router.js +++ b/services/real-time/app/coffee/Router.js @@ -1,3 +1,10 @@ +/* eslint-disable + camelcase, + handle-callback-err, + standard/no-callback-literal, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from @@ -29,7 +36,7 @@ module.exports = (Router = { _handleError(callback, error, client, method, attrs) { if (callback == null) { callback = function(error) {}; } if (attrs == null) { attrs = {}; } - for (let key of ["project_id", "doc_id", "user_id"]) { + for (const key of ["project_id", "doc_id", "user_id"]) { attrs[key] = client.ol_context[key]; } attrs.client_id = client.id; diff --git a/services/real-time/app/coffee/SafeJsonParse.js b/services/real-time/app/coffee/SafeJsonParse.js index 4c058053b7..f5e8dd3797 100644 --- a/services/real-time/app/coffee/SafeJsonParse.js +++ b/services/real-time/app/coffee/SafeJsonParse.js @@ -1,3 +1,8 @@ +/* eslint-disable + handle-callback-err, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns diff --git a/services/real-time/app/coffee/SessionSockets.js b/services/real-time/app/coffee/SessionSockets.js index 533fed3d4c..894c7b53d5 100644 --- a/services/real-time/app/coffee/SessionSockets.js +++ b/services/real-time/app/coffee/SessionSockets.js @@ -1,3 +1,5 @@ +// TODO: This file was created by bulk-decaffeinate. +// Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns diff --git a/services/real-time/app/coffee/WebApiManager.js b/services/real-time/app/coffee/WebApiManager.js index 489d4c0a7b..9598d83106 100644 --- a/services/real-time/app/coffee/WebApiManager.js +++ b/services/real-time/app/coffee/WebApiManager.js @@ -1,3 +1,10 @@ +/* eslint-disable + camelcase, + handle-callback-err, + no-unused-vars, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns @@ -34,7 +41,7 @@ module.exports = (WebApiManager = { }, function(error, response, data) { let err; if (error != null) { return callback(error); } - if (200 <= response.statusCode && response.statusCode < 300) { + if (response.statusCode >= 200 && response.statusCode < 300) { if ((data == null) || ((data != null ? data.project : undefined) == null)) { err = new Error('no data returned from joinProject request'); logger.error({err, project_id, user_id}, "error accessing web api"); diff --git a/services/real-time/app/coffee/WebsocketController.js b/services/real-time/app/coffee/WebsocketController.js index dcd6955ac7..aa51bbb372 100644 --- a/services/real-time/app/coffee/WebsocketController.js +++ b/services/real-time/app/coffee/WebsocketController.js @@ -1,3 +1,10 @@ +/* eslint-disable + camelcase, + handle-callback-err, + no-unused-vars, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from @@ -47,17 +54,17 @@ module.exports = (WebsocketController = { } client.ol_context = {}; - client.ol_context["privilege_level"] = privilegeLevel; - client.ol_context["user_id"] = user_id; - client.ol_context["project_id"] = project_id; - client.ol_context["owner_id"] = __guard__(project != null ? project.owner : undefined, x => x._id); - client.ol_context["first_name"] = user != null ? user.first_name : undefined; - client.ol_context["last_name"] = user != null ? user.last_name : undefined; - client.ol_context["email"] = user != null ? user.email : undefined; - client.ol_context["connected_time"] = new Date(); - client.ol_context["signup_date"] = user != null ? user.signUpDate : undefined; - client.ol_context["login_count"] = user != null ? user.loginCount : undefined; - client.ol_context["is_restricted_user"] = !!(isRestrictedUser); + client.ol_context.privilege_level = privilegeLevel; + client.ol_context.user_id = user_id; + client.ol_context.project_id = project_id; + client.ol_context.owner_id = __guard__(project != null ? project.owner : undefined, x => x._id); + client.ol_context.first_name = user != null ? user.first_name : undefined; + client.ol_context.last_name = user != null ? user.last_name : undefined; + client.ol_context.email = user != null ? user.email : undefined; + client.ol_context.connected_time = new Date(); + client.ol_context.signup_date = user != null ? user.signUpDate : undefined; + client.ol_context.login_count = user != null ? user.loginCount : undefined; + client.ol_context.is_restricted_user = !!(isRestrictedUser); RoomManager.joinProject(client, project_id, function(err) { if (err) { return callback(err); } @@ -73,7 +80,7 @@ module.exports = (WebsocketController = { // We want to flush a project if there are no more (local) connected clients // but we need to wait for the triggering client to disconnect. How long we wait // is determined by FLUSH_IF_EMPTY_DELAY. - FLUSH_IF_EMPTY_DELAY: 500, //ms + FLUSH_IF_EMPTY_DELAY: 500, // ms leaveProject(io, client, callback) { if (callback == null) { callback = function(error) {}; } const {project_id, user_id} = client.ol_context; @@ -160,10 +167,10 @@ module.exports = (WebsocketController = { } if (options.encodeRanges) { try { - for (let comment of Array.from((ranges != null ? ranges.comments : undefined) || [])) { + for (const comment of Array.from((ranges != null ? ranges.comments : undefined) || [])) { if (comment.op.c != null) { comment.op.c = encodeForWebsockets(comment.op.c); } } - for (let change of Array.from((ranges != null ? ranges.changes : undefined) || [])) { + for (const change of Array.from((ranges != null ? ranges.changes : undefined) || [])) { if (change.op.i != null) { change.op.i = encodeForWebsockets(change.op.i); } if (change.op.d != null) { change.op.d = encodeForWebsockets(change.op.d); } } @@ -192,7 +199,7 @@ module.exports = (WebsocketController = { // we could remove permission when user leaves a doc, but because // the connection is per-project, we continue to allow access // after the initial joinDoc since we know they are already authorised. - //# AuthorizationManager.removeAccessToDoc client, doc_id + // # AuthorizationManager.removeAccessToDoc client, doc_id return callback(); }, updateClientPosition(client, cursorData, callback) { @@ -221,12 +228,7 @@ module.exports = (WebsocketController = { } else { cursorData.name = first_name && last_name ? `${first_name} ${last_name}` - : first_name ? - first_name - : last_name ? - last_name - : - ""; + : first_name || (last_name || ""); ConnectedUsersManager.updateUserPosition(project_id, client.publicId, { first_name, last_name, @@ -340,7 +342,7 @@ module.exports = (WebsocketController = { }, _isCommentUpdate(update) { - for (let op of Array.from(update.op)) { + for (const op of Array.from(update.op)) { if ((op.c == null)) { return false; } diff --git a/services/real-time/app/coffee/WebsocketLoadBalancer.js b/services/real-time/app/coffee/WebsocketLoadBalancer.js index 0734929453..dc2617742a 100644 --- a/services/real-time/app/coffee/WebsocketLoadBalancer.js +++ b/services/real-time/app/coffee/WebsocketLoadBalancer.js @@ -1,3 +1,8 @@ +/* eslint-disable + camelcase, +*/ +// TODO: This file was created by bulk-decaffeinate. +// Fix any style issues and re-enable lint. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from @@ -55,7 +60,7 @@ module.exports = (WebsocketLoadBalancer = { listenForEditorEvents(io) { logger.log({rclients: this.rclientPubList.length}, "publishing editor events"); logger.log({rclients: this.rclientSubList.length}, "listening for editor events"); - for (let rclientSub of Array.from(this.rclientSubList)) { + for (const rclientSub of Array.from(this.rclientSubList)) { rclientSub.subscribe("editor-events"); rclientSub.on("message", function(channel, message) { if (Settings.debugEvents > 0) { EventLogger.debugEvent(channel, message); } @@ -113,7 +118,7 @@ module.exports = (WebsocketLoadBalancer = { // send messages only to unique clients (due to duplicate entries in io.sockets.clients) clientList = io.sockets.clients(message.room_id) - .filter(client => !(is_restricted_message && client.ol_context['is_restricted_user'])); + .filter(client => !(is_restricted_message && client.ol_context.is_restricted_user)); // avoid unnecessary work if no clients are connected if (clientList.length === 0) { return; }