Преглед изворни кода

decaffeinate: Run post-processing cleanups on AuthorizationManager.coffee and 18 other files

decaffeinate пре 6 година
родитељ
комит
a397154e18

+ 7 - 1
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"));

+ 5 - 0
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

+ 6 - 0
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

+ 7 - 1
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());

+ 9 - 2
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 {

+ 6 - 1
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");

+ 6 - 0
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);

+ 6 - 1
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];

+ 11 - 1
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; }
         }

+ 7 - 1
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 {

+ 7 - 1
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 /

+ 6 - 1
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"

+ 8 - 2
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));

+ 8 - 1
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;

+ 5 - 0
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

+ 2 - 0
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

+ 8 - 1
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");

+ 24 - 22
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;
 			}

+ 7 - 2
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; }