mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 08:26:16 -04:00
lint: src/node/db/AuthorManager.js
This commit is contained in:
parent
d9225f326f
commit
8aa729a36f
1 changed files with 89 additions and 100 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
'use strict';
|
||||||
/**
|
/**
|
||||||
* The AuthorManager controlls all information about the Pad authors
|
* The AuthorManager controlls all information about the Pad authors
|
||||||
*/
|
*/
|
||||||
|
@ -19,85 +20,83 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const db = require('./DB');
|
const db = require('./DB');
|
||||||
const customError = require('../utils/customError');
|
const CustomError = require('../utils/customError');
|
||||||
const randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
const randomString = require('../../static/js/pad_utils').randomString;
|
||||||
|
|
||||||
exports.getColorPalette = function () {
|
exports.getColorPalette = () => [
|
||||||
return [
|
'#ffc7c7',
|
||||||
'#ffc7c7',
|
'#fff1c7',
|
||||||
'#fff1c7',
|
'#e3ffc7',
|
||||||
'#e3ffc7',
|
'#c7ffd5',
|
||||||
'#c7ffd5',
|
'#c7ffff',
|
||||||
'#c7ffff',
|
'#c7d5ff',
|
||||||
'#c7d5ff',
|
'#e3c7ff',
|
||||||
'#e3c7ff',
|
'#ffc7f1',
|
||||||
'#ffc7f1',
|
'#ffa8a8',
|
||||||
'#ffa8a8',
|
'#ffe699',
|
||||||
'#ffe699',
|
'#cfff9e',
|
||||||
'#cfff9e',
|
'#99ffb3',
|
||||||
'#99ffb3',
|
'#a3ffff',
|
||||||
'#a3ffff',
|
'#99b3ff',
|
||||||
'#99b3ff',
|
'#cc99ff',
|
||||||
'#cc99ff',
|
'#ff99e5',
|
||||||
'#ff99e5',
|
'#e7b1b1',
|
||||||
'#e7b1b1',
|
'#e9dcAf',
|
||||||
'#e9dcAf',
|
'#cde9af',
|
||||||
'#cde9af',
|
'#bfedcc',
|
||||||
'#bfedcc',
|
'#b1e7e7',
|
||||||
'#b1e7e7',
|
'#c3cdee',
|
||||||
'#c3cdee',
|
'#d2b8ea',
|
||||||
'#d2b8ea',
|
'#eec3e6',
|
||||||
'#eec3e6',
|
'#e9cece',
|
||||||
'#e9cece',
|
'#e7e0ca',
|
||||||
'#e7e0ca',
|
'#d3e5c7',
|
||||||
'#d3e5c7',
|
'#bce1c5',
|
||||||
'#bce1c5',
|
'#c1e2e2',
|
||||||
'#c1e2e2',
|
'#c1c9e2',
|
||||||
'#c1c9e2',
|
'#cfc1e2',
|
||||||
'#cfc1e2',
|
'#e0bdd9',
|
||||||
'#e0bdd9',
|
'#baded3',
|
||||||
'#baded3',
|
'#a0f8eb',
|
||||||
'#a0f8eb',
|
'#b1e7e0',
|
||||||
'#b1e7e0',
|
'#c3c8e4',
|
||||||
'#c3c8e4',
|
'#cec5e2',
|
||||||
'#cec5e2',
|
'#b1d5e7',
|
||||||
'#b1d5e7',
|
'#cda8f0',
|
||||||
'#cda8f0',
|
'#f0f0a8',
|
||||||
'#f0f0a8',
|
'#f2f2a6',
|
||||||
'#f2f2a6',
|
'#f5a8eb',
|
||||||
'#f5a8eb',
|
'#c5f9a9',
|
||||||
'#c5f9a9',
|
'#ececbb',
|
||||||
'#ececbb',
|
'#e7c4bc',
|
||||||
'#e7c4bc',
|
'#daf0b2',
|
||||||
'#daf0b2',
|
'#b0a0fd',
|
||||||
'#b0a0fd',
|
'#bce2e7',
|
||||||
'#bce2e7',
|
'#cce2bb',
|
||||||
'#cce2bb',
|
'#ec9afe',
|
||||||
'#ec9afe',
|
'#edabbd',
|
||||||
'#edabbd',
|
'#aeaeea',
|
||||||
'#aeaeea',
|
'#c4e7b1',
|
||||||
'#c4e7b1',
|
'#d722bb',
|
||||||
'#d722bb',
|
'#f3a5e7',
|
||||||
'#f3a5e7',
|
'#ffa8a8',
|
||||||
'#ffa8a8',
|
'#d8c0c5',
|
||||||
'#d8c0c5',
|
'#eaaedd',
|
||||||
'#eaaedd',
|
'#adc6eb',
|
||||||
'#adc6eb',
|
'#bedad1',
|
||||||
'#bedad1',
|
'#dee9af',
|
||||||
'#dee9af',
|
'#e9afc2',
|
||||||
'#e9afc2',
|
'#f8d2a0',
|
||||||
'#f8d2a0',
|
'#b3b3e6',
|
||||||
'#b3b3e6',
|
];
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the author exists
|
* Checks if the author exists
|
||||||
*/
|
*/
|
||||||
exports.doesAuthorExist = async function (authorID) {
|
exports.doesAuthorExist = async (authorID) => {
|
||||||
const author = await db.get(`globalAuthor:${authorID}`);
|
const author = await db.get(`globalAuthor:${authorID}`);
|
||||||
|
|
||||||
return author !== null;
|
return author != null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* exported for backwards compatibility */
|
/* exported for backwards compatibility */
|
||||||
|
@ -107,7 +106,7 @@ exports.doesAuthorExists = exports.doesAuthorExist;
|
||||||
* Returns the AuthorID for a token.
|
* Returns the AuthorID for a token.
|
||||||
* @param {String} token The token
|
* @param {String} token The token
|
||||||
*/
|
*/
|
||||||
exports.getAuthor4Token = async function (token) {
|
exports.getAuthor4Token = async (token) => {
|
||||||
const author = await mapAuthorWithDBKey('token2author', token);
|
const author = await mapAuthorWithDBKey('token2author', token);
|
||||||
|
|
||||||
// return only the sub value authorID
|
// return only the sub value authorID
|
||||||
|
@ -119,7 +118,7 @@ exports.getAuthor4Token = async function (token) {
|
||||||
* @param {String} token The mapper
|
* @param {String} token The mapper
|
||||||
* @param {String} name The name of the author (optional)
|
* @param {String} name The name of the author (optional)
|
||||||
*/
|
*/
|
||||||
exports.createAuthorIfNotExistsFor = async function (authorMapper, name) {
|
exports.createAuthorIfNotExistsFor = async (authorMapper, name) => {
|
||||||
const author = await mapAuthorWithDBKey('mapper2author', authorMapper);
|
const author = await mapAuthorWithDBKey('mapper2author', authorMapper);
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
|
@ -140,7 +139,7 @@ async function mapAuthorWithDBKey(mapperkey, mapper) {
|
||||||
// try to map to an author
|
// try to map to an author
|
||||||
const 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
|
// there is no author with this mapper, so create one
|
||||||
const author = await exports.createAuthor(null);
|
const author = await exports.createAuthor(null);
|
||||||
|
|
||||||
|
@ -163,7 +162,7 @@ async function mapAuthorWithDBKey(mapperkey, mapper) {
|
||||||
* Internal function that creates the database entry for an author
|
* Internal function that creates the database entry for an author
|
||||||
* @param {String} name The name of the author
|
* @param {String} name The name of the author
|
||||||
*/
|
*/
|
||||||
exports.createAuthor = function (name) {
|
exports.createAuthor = (name) => {
|
||||||
// create the new author name
|
// create the new author name
|
||||||
const author = `a.${randomString(16)}`;
|
const author = `a.${randomString(16)}`;
|
||||||
|
|
||||||
|
@ -185,50 +184,40 @@ exports.createAuthor = function (name) {
|
||||||
* Returns the Author Obj of the author
|
* Returns the Author Obj of the author
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
*/
|
*/
|
||||||
exports.getAuthor = function (author) {
|
exports.getAuthor = (author) => db.get(`globalAuthor:${author}`);
|
||||||
// NB: result is already a Promise
|
|
||||||
return db.get(`globalAuthor:${author}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the color Id of the author
|
* Returns the color Id of the author
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
*/
|
*/
|
||||||
exports.getAuthorColorId = function (author) {
|
exports.getAuthorColorId = (author) => db.getSub(`globalAuthor:${author}`, ['colorId']);
|
||||||
return db.getSub(`globalAuthor:${author}`, ['colorId']);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the color Id of the author
|
* Sets the color Id of the author
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
* @param {String} colorId The color id of the author
|
* @param {String} colorId The color id of the author
|
||||||
*/
|
*/
|
||||||
exports.setAuthorColorId = function (author, colorId) {
|
exports.setAuthorColorId = (author, colorId) => db.setSub(
|
||||||
return db.setSub(`globalAuthor:${author}`, ['colorId'], colorId);
|
`globalAuthor:${author}`, ['colorId'], colorId);
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the author
|
* Returns the name of the author
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
*/
|
*/
|
||||||
exports.getAuthorName = function (author) {
|
exports.getAuthorName = (author) => db.getSub(`globalAuthor:${author}`, ['name']);
|
||||||
return db.getSub(`globalAuthor:${author}`, ['name']);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the name of the author
|
* Sets the name of the author
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
* @param {String} name The name of the author
|
* @param {String} name The name of the author
|
||||||
*/
|
*/
|
||||||
exports.setAuthorName = function (author, name) {
|
exports.setAuthorName = (author, name) => db.setSub(`globalAuthor:${author}`, ['name'], name);
|
||||||
return db.setSub(`globalAuthor:${author}`, ['name'], name);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of all pads this author contributed to
|
* Returns an array of all pads this author contributed to
|
||||||
* @param {String} author The id of the author
|
* @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:
|
/* 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
|
* (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
|
* (2) When a pad is deleted, each author of that pad is also updated
|
||||||
|
@ -237,9 +226,9 @@ exports.listPadsOfAuthor = async function (authorID) {
|
||||||
// get the globalAuthor
|
// get the globalAuthor
|
||||||
const author = await db.get(`globalAuthor:${authorID}`);
|
const author = await db.get(`globalAuthor:${authorID}`);
|
||||||
|
|
||||||
if (author === null) {
|
if (author == null) {
|
||||||
// author does not exist
|
// 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
|
// everything is fine, return the pad IDs
|
||||||
|
@ -253,11 +242,11 @@ exports.listPadsOfAuthor = async function (authorID) {
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
* @param {String} padID The id of the pad the author contributes to
|
* @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
|
// get the entry
|
||||||
const 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
|
* ACHTUNG: padIDs can also be undefined, not just null, so it is not possible
|
||||||
|
@ -280,12 +269,12 @@ exports.addPad = async function (authorID, padID) {
|
||||||
* @param {String} author The id of the author
|
* @param {String} author The id of the author
|
||||||
* @param {String} padID The id of the pad the author contributes to
|
* @param {String} padID The id of the pad the author contributes to
|
||||||
*/
|
*/
|
||||||
exports.removePad = async function (authorID, padID) {
|
exports.removePad = async (authorID, padID) => {
|
||||||
const author = await db.get(`globalAuthor:${authorID}`);
|
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
|
// remove pad from author
|
||||||
delete author.padIDs[padID];
|
delete author.padIDs[padID];
|
||||||
await db.set(`globalAuthor:${authorID}`, author);
|
await db.set(`globalAuthor:${authorID}`, author);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue