From 8c61948d02e40fd13e2d0cf2154c34df62add47e Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 30 Apr 2021 14:48:22 +0530 Subject: [PATCH] implement SET_ADMIN_EMAIL and SET_SUPPORT_MAILBOX decrees and update changelog --- CHANGELOG.md | 9 +++++++++ lib/commands/core.js | 4 ++++ lib/decrees.js | 43 ++++++++++++++++++++++++++++++++----------- lib/metadata.js | 5 ++--- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b6a59683..ea1d3ced2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ * reminders in calendars * import/export * include LICENSE for ical.js + * translations + * out of BETA + * available from user admin menu * use a specific version of bootstrap-tokenfield in bower.json * don't create readmes * support displaying a roadmap in static pages' footer @@ -18,6 +21,12 @@ * lock sheets faster when applying checkpoints * guard against undefined checkpoints * don't spam users with prompts to checkpoints when they can't +* decrees + * SET_ADMIN_EMAIL + * SET_SUPPORT_MAILBOX +* Add DAPSI to our sponsor list +* checkup + * check for duplicate or incorrect headers # 4.4.0 diff --git a/lib/commands/core.js b/lib/commands/core.js index 42ed0455b..a0be7cd67 100644 --- a/lib/commands/core.js +++ b/lib/commands/core.js @@ -13,6 +13,10 @@ Core.isValidId = function (chan) { [32, 33, 48].indexOf(chan.length) > -1; }; +Core.isValidPublicKey = function (owner) { + return typeof(owner) === 'string' && owner.length === 44; +}; + var makeToken = Core.makeToken = function () { return Number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)) .toString(16); diff --git a/lib/decrees.js b/lib/decrees.js index fca8fb331..eed840057 100644 --- a/lib/decrees.js +++ b/lib/decrees.js @@ -1,4 +1,5 @@ var Decrees = module.exports; +var Core = require("./commands/core"); /* Admin decrees which modify global server state @@ -29,6 +30,10 @@ SET_LAST_BROADCAST_HASH SET_SURVEY_URL SET_MAINTENANCE +// EASIER CONFIG +SET_ADMIN_EMAIL +SET_SUPPORT_MAILBOX + NOT IMPLEMENTED: // RESTRICTED REGISTRATION @@ -37,9 +42,11 @@ REVOKE_INVITE REDEEM_INVITE // 2.0 -Env.adminEmail -Env.supportMailbox Env.DEV_MODE || Env.FRESH_MODE, + +ADD_ADMIN_KEY +RM_ADMIN_KEY + */ var commands = {}; @@ -88,6 +95,20 @@ var isNonNegativeNumber = function (n) { }; */ +var default_validator = function () { return true; }; +var makeGenericSetter = function (attr, validator) { + validator = validator || default_validator; + return function (Env, args) { + if (!validator(args)) { + throw new Error("INVALID_ARGS"); + } + var value = args[0]; + if (value === Env[attr]) { return false; } + Env[attr] = value; + return true; + }; +}; + var isInteger = function (n) { return !(typeof(n) !== 'number' || isNaN(n) || (n % 1) !== 0); }; @@ -97,15 +118,7 @@ var args_isInteger = function (args) { }; var makeIntegerSetter = function (attr) { - return function (Env, args) { - if (!args_isInteger(args)) { - throw new Error('INVALID_ARGS'); - } - var integer = args[0]; - if (integer === Env[attr]) { return false; } - Env[attr] = integer; - return true; - }; + return makeGenericSetter(attr, args_isInteger); }; // CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['SET_MAX_UPLOAD_SIZE', [50 * 1024 * 1024]]], console.log) @@ -130,6 +143,14 @@ var args_isString = function (args) { return Array.isArray(args) && typeof(args[0]) === "string"; }; +// CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['SET_ADMIN_EMAIL', ['admin@website.tld']]], console.log) +commands.SET_ADMIN_EMAIL = makeGenericSetter('adminEmail', args_isString); + +// CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['SET_SUPPORT_MAILBOX', ["Tdz6+fE9N9XXBY93rW5qeNa/k27yd40c0vq7EJyt7jA="]]], console.log) +commands.SET_SUPPORT_MAILBOX = makeGenericSetter('supportMailbox', function (args) { + return args_isString(args) && Core.isValidPublicKey(args[0]); +}); + // Maintenance: Empty string or an object with a start and end time var isNumber = function (value) { return typeof(value) === "number" && !isNaN(value); diff --git a/lib/metadata.js b/lib/metadata.js index 97f2e484a..d320a5c9b 100644 --- a/lib/metadata.js +++ b/lib/metadata.js @@ -1,4 +1,5 @@ var Meta = module.exports; +var Core = require("./commands/core"); var deduplicate = require("./common-util").deduplicateString; @@ -35,9 +36,7 @@ the owners field is guaranteed to exist. var commands = {}; -var isValidPublicKey = function (owner) { - return typeof(owner) === 'string' && owner.length === 44; -}; +var isValidPublicKey = Core.isValidPublicKey; // isValidPublicKey is a better indication of what the above function does // I'm preserving this function name in case we ever want to expand its