Index: lams_build/conf/etherpad/etherpad-lite/src/node/db/AuthorManager.js =================================================================== diff -u -r6c35e7bbcc3c98e9e3a1c31a367c44cb87bdf987 -re58a530f572d8cd8270992438502f2307870c81a --- lams_build/conf/etherpad/etherpad-lite/src/node/db/AuthorManager.js (.../AuthorManager.js) (revision 6c35e7bbcc3c98e9e3a1c31a367c44cb87bdf987) +++ lams_build/conf/etherpad/etherpad-lite/src/node/db/AuthorManager.js (.../AuthorManager.js) (revision e58a530f572d8cd8270992438502f2307870c81a) @@ -1,3 +1,4 @@ +'use strict'; /** * The AuthorManager controlls all information about the Pad authors */ @@ -18,24 +19,21 @@ * limitations under the License. */ -var db = require("./DB"); -var customError = require("../utils/customError"); -var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString; +const db = require('./DB'); +const CustomError = require('../utils/customError'); +const randomString = require('../../static/js/pad_utils').randomString; -exports.getColorPalette = function() { - //*LAMS* modified the following array: replaced dark colors with the more lighter ones - return ["#ffc7c7", "#fff1c7", "#e3ffc7", "#c7ffd5", "#c7ffff", "#c7d5ff", "#e3c7ff", "#ffc7f1", "#ff8f8f", "#ffe38f", "#c7ff8f", "#8fffab", "#8fffff", "#8fabff", "#c78fff", "#ff8fe3", "#ecbcbc", "#d9c179", "#a9d979", "#79d991", "#79d9d9", "#bcc8ec", "#dcc9ef", "#efc9e6", "#d9a9a9", "#d9cda9", "#c1d9a9", "#a9d9b5", "#a9d9d9", "#a9b5d9", "#c1a9d9", "#d9a9cd", "#c9e1d9", "#12d1ad", "#d5e8e5", "#d5daed", "#a091c7", "#c1dae5", "#e0d0f0", "#e6e76d", "#e3bfd0", "#f386e5", "#4ecc0c", "#c0c236", "#d2c1bd", "#b5de6a", "#9b88fd", "#c2dde1", "#c8d3c0", "#e267fe", "#f1c0cc", "#babad0", "#cde3c2", "#f7d2f1", "#86dc6c", "#b5a714", "#dfcdd2", "#ebd4e6", "#4b81c8", "#c4d2cd", "#c6c9b9", "#d16084", "#efe1ce", "#8c8bd8"]; -}; +//*LAMS* modified the following array: replaced dark colors with the more lighter ones +exports.getColorPalette = () => ["#ffc7c7", "#fff1c7", "#e3ffc7", "#c7ffd5", "#c7ffff", "#c7d5ff", "#e3c7ff", "#ffc7f1", "#ff8f8f", "#ffe38f", "#c7ff8f", "#8fffab", "#8fffff", "#8fabff", "#c78fff", "#ff8fe3", "#ecbcbc", "#d9c179", "#a9d979", "#79d991", "#79d9d9", "#bcc8ec", "#dcc9ef", "#efc9e6", "#d9a9a9", "#d9cda9", "#c1d9a9", "#a9d9b5", "#a9d9d9", "#a9b5d9", "#c1a9d9", "#d9a9cd", "#c9e1d9", "#12d1ad", "#d5e8e5", "#d5daed", "#a091c7", "#c1dae5", "#e0d0f0", "#e6e76d", "#e3bfd0", "#f386e5", "#4ecc0c", "#c0c236", "#d2c1bd", "#b5de6a", "#9b88fd", "#c2dde1", "#c8d3c0", "#e267fe", "#f1c0cc", "#babad0", "#cde3c2", "#f7d2f1", "#86dc6c", "#b5a714", "#dfcdd2", "#ebd4e6", "#4b81c8", "#c4d2cd", "#c6c9b9", "#d16084", "#efe1ce", "#8c8bd8"]; /** * Checks if the author exists */ -exports.doesAuthorExist = async function(authorID) -{ - let author = await db.get("globalAuthor:" + authorID); +exports.doesAuthorExist = async (authorID) => { + const author = await db.get(`globalAuthor:${authorID}`); - return author !== null; -} + return author != null; +}; /* exported for backwards compatibility */ exports.doesAuthorExists = exports.doesAuthorExist; @@ -44,22 +42,20 @@ * Returns the AuthorID for a token. * @param {String} token The token */ -exports.getAuthor4Token = async function(token) -{ - let author = await mapAuthorWithDBKey("token2author", token); +exports.getAuthor4Token = async (token) => { + const author = await mapAuthorWithDBKey('token2author', token); // return only the sub value authorID return author ? author.authorID : author; -} +}; /** * Returns the AuthorID for a mapper. * @param {String} token The mapper * @param {String} name The name of the author (optional) */ -exports.createAuthorIfNotExistsFor = async function(authorMapper, name) -{ - let author = await mapAuthorWithDBKey("mapper2author", authorMapper); +exports.createAuthorIfNotExistsFor = async (authorMapper, name) => { + const author = await mapAuthorWithDBKey('mapper2author', authorMapper); if (name) { // set the name of this author @@ -75,137 +71,118 @@ * @param {String} mapperkey The database key name for this mapper * @param {String} mapper The mapper */ -async function mapAuthorWithDBKey (mapperkey, mapper) -{ +const mapAuthorWithDBKey = async (mapperkey, mapper) => { // try to map to an author - let author = await db.get(mapperkey + ":" + mapper); + const author = await db.get(`${mapperkey}:${mapper}`); - if (author === null) { + if (author == null) { // there is no author with this mapper, so create one - let author = await exports.createAuthor(null); + const author = await exports.createAuthor(null); // create the token2author relation - await db.set(mapperkey + ":" + mapper, author.authorID); + await db.set(`${mapperkey}:${mapper}`, author.authorID); // return the author return author; } // there is an author with this mapper // update the timestamp of this author - await db.setSub("globalAuthor:" + author, ["timestamp"], Date.now()); + await db.setSub(`globalAuthor:${author}`, ['timestamp'], Date.now()); // return the author - return { authorID: author}; -} + return {authorID: author}; +}; /** * Internal function that creates the database entry for an author * @param {String} name The name of the author */ -exports.createAuthor = function(name) -{ +exports.createAuthor = async (name) => { // create the new author name - let author = "a." + randomString(16); + const author = `a.${randomString(16)}`; // create the globalAuthors db entry - let authorObj = { - "colorId": Math.floor(Math.random() * (exports.getColorPalette().length)), - "name": name, - "timestamp": Date.now() + const authorObj = { + colorId: Math.floor(Math.random() * (exports.getColorPalette().length)), + name, + timestamp: Date.now(), }; // set the global author db entry - // NB: no await, since we're not waiting for the DB set to finish - db.set("globalAuthor:" + author, authorObj); + await db.set(`globalAuthor:${author}`, authorObj); - return { authorID: author }; -} + return {authorID: author}; +}; /** * Returns the Author Obj of the author * @param {String} author The id of the author */ -exports.getAuthor = function(author) -{ - // NB: result is already a Promise - return db.get("globalAuthor:" + author); -} +exports.getAuthor = async (author) => await db.get(`globalAuthor:${author}`); /** * Returns the color Id of the author * @param {String} author The id of the author */ -exports.getAuthorColorId = function(author) -{ - return db.getSub("globalAuthor:" + author, ["colorId"]); -} +exports.getAuthorColorId = async (author) => await db.getSub(`globalAuthor:${author}`, ['colorId']); /** * Sets the color Id of the author * @param {String} author The id of the author * @param {String} colorId The color id of the author */ -exports.setAuthorColorId = function(author, colorId) -{ - return db.setSub("globalAuthor:" + author, ["colorId"], colorId); -} +exports.setAuthorColorId = async (author, colorId) => await db.setSub( + `globalAuthor:${author}`, ['colorId'], colorId); /** * Returns the name of the author * @param {String} author The id of the author */ -exports.getAuthorName = function(author) -{ - return db.getSub("globalAuthor:" + author, ["name"]); -} +exports.getAuthorName = async (author) => await db.getSub(`globalAuthor:${author}`, ['name']); /** * Sets the name of the author * @param {String} author The id of the author * @param {String} name The name of the author */ -exports.setAuthorName = function(author, name) -{ - return db.setSub("globalAuthor:" + author, ["name"], name); -} +exports.setAuthorName = async (author, name) => await db.setSub( + `globalAuthor:${author}`, ['name'], name); /** * Returns an array of all pads this author contributed to * @param {String} author The id of the author */ -exports.listPadsOfAuthor = async function(authorID) -{ +exports.listPadsOfAuthor = async (authorID) => { /* There are two other places where this array is manipulated: * (1) When the author is added to a pad, the author object is also updated * (2) When a pad is deleted, each author of that pad is also updated */ // get the globalAuthor - let author = await db.get("globalAuthor:" + authorID); + const author = await db.get(`globalAuthor:${authorID}`); - if (author === null) { + if (author == null) { // author does not exist - throw new customError("authorID does not exist", "apierror"); + throw new CustomError('authorID does not exist', 'apierror'); } // everything is fine, return the pad IDs - let padIDs = Object.keys(author.padIDs || {}); + const padIDs = Object.keys(author.padIDs || {}); - return { padIDs }; -} + return {padIDs}; +}; /** * Adds a new pad to the list of contributions * @param {String} author The id of the author * @param {String} padID The id of the pad the author contributes to */ -exports.addPad = async function(authorID, padID) -{ +exports.addPad = async (authorID, padID) => { // get the entry - let author = await db.get("globalAuthor:" + authorID); + const author = await db.get(`globalAuthor:${authorID}`); - if (author === null) return; + if (author == null) return; /* * ACHTUNG: padIDs can also be undefined, not just null, so it is not possible @@ -220,23 +197,22 @@ author.padIDs[padID] = 1; // anything, because value is not used // save the new element back - db.set("globalAuthor:" + authorID, author); -} + await db.set(`globalAuthor:${authorID}`, author); +}; /** * Removes a pad from the list of contributions * @param {String} author The id of the author * @param {String} padID The id of the pad the author contributes to */ -exports.removePad = async function(authorID, padID) -{ - let author = await db.get("globalAuthor:" + authorID); +exports.removePad = async (authorID, padID) => { + const author = await db.get(`globalAuthor:${authorID}`); - if (author === null) return; + if (author == null) return; - if (author.padIDs !== null) { + if (author.padIDs != null) { // remove pad from author delete author.padIDs[padID]; - db.set("globalAuthor:" + authorID, author); + await db.set(`globalAuthor:${authorID}`, author); } -} +};