var Decrees = module.exports; /* Admin decrees which modify global server state IMPLEMENTED: RESTRICT_REGISTRATION() UPDATE_DEFAULT_STORAGE() NOT IMPLEMENTED: // QUOTA MANAGEMENT ADD_QUOTA RM_QUOTA() UPDATE_QUOTA // RESTRICTED REGISTRATION ADD_INVITE REVOKE_INVITE REDEEM_INVITE // 2.0 UPDATE_INACTIVE_TIME UPDATE_ACCOUNT_RETENTION_TIME UPDATE_ARCHIVE_RETENTION_TIME // 3.0 UPDATE_MAX_UPLOAD_SIZE UPDATE_PREMIUM_UPLOAD_SIZE */ var commands = {}; /* commands have a simple API: * they receive the global Env and the arguments to be applied * if the arguments are invalid the operation will not be applied * the command throws * if the arguments are valid but do not result in a change, the operation is redundant. * return false * if the arguments are valid and will result in a change, the operation should be applied * apply it * return true to indicate that it was applied */ // Toggles a simple boolean // CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['RESTRICT_REGISTRATION', [true]]], console.log) commands.RESTRICT_REGISTRATION = function (Env, args) { if (!Array.isArray(args) || typeof(args[0]) !== 'boolean') { throw new Error('INVALID_ARGS'); } var bool = args[0]; if (bool === Env.restrictRegistration) { return false; } Env.restrictRegistration = bool; return true; }; var isNonNegativeNumber = function (n) { return !(typeof(n) !== 'number' || isNaN(n) || n < 0); }; // CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['UPDATE_DEFAULT_STORAGE', [100 * 1024 * 1024]]], console.log) commands.UPDATE_DEFAULT_STORAGE = function (Env, args) { if (!Array.isArray(args) || !isNonNegativeNumber(args[0])) { throw new Error('INVALID_ARGS'); } var limit = args[0]; if (limit === Env.defaultStorageLimit) { return false; } Env.defaultStorageLimit = limit; return true; }; //var Quota = require("./commands/quota"); commands.ADD_QUOTA = function (Env, args) { args = args; throw new Error("NOT_IMPLEMENTED"); }; commands.RM_QUOTA = function (Env, args) { args = args; throw new Error("NOT_IMPLEMENTED"); }; commands.UPDATE_QUOTA = function (Env, args) { args = args; throw new Error("NOT_IMPLEMENTED"); }; // [, , ,