implement GET_LIMITS admin rpc

...and label stored usage limits according to their source
pull/1/head
ansuz 4 years ago
parent 5029281a53
commit 928b7e3583

@ -225,6 +225,11 @@ var instanceStatus = function (Env, Server, cb) {
}); });
}; };
// CryptPad_AsyncStore.rpc.send('ADMIN', ['LIST_LIMITS'], console.log)
var getLimits = function (Env, Server, cb) {
cb(void 0, Env.limits);
};
var commands = { var commands = {
ACTIVE_SESSIONS: getActiveSessions, ACTIVE_SESSIONS: getActiveSessions,
ACTIVE_PADS: getActiveChannelCount, ACTIVE_PADS: getActiveChannelCount,
@ -241,6 +246,7 @@ var commands = {
ADMIN_DECREE: adminDecree, ADMIN_DECREE: adminDecree,
INSTANCE_STATUS: instanceStatus, INSTANCE_STATUS: instanceStatus,
GET_LIMITS: getLimits,
}; };
Admin.command = function (Env, safeKey, data, _cb, Server) { Admin.command = function (Env, safeKey, data, _cb, Server) {

@ -8,7 +8,7 @@ const Package = require('../../package.json');
const Https = require("https"); const Https = require("https");
const Util = require("../common-util"); const Util = require("../common-util");
var validLimitFields = ['limit', 'plan', 'note', 'users']; var validLimitFields = ['limit', 'plan', 'note', 'users', 'origin'];
Quota.isValidLimit = function (o) { Quota.isValidLimit = function (o) {
var valid = o && typeof(o) === 'object' && var valid = o && typeof(o) === 'object' &&
@ -137,7 +137,14 @@ Quota.updateCachedLimits = function (Env, cb) {
if (err) { return void cb(err); } if (err) { return void cb(err); }
if (!json) { return void cb(); } if (!json) { return void cb(); }
for (var k in json) {
if (k.length === 44 && json[k]) {
json[k].origin = 'remote';
}
}
Env.limits = json; Env.limits = json;
Quota.applyCustomLimits(Env); Quota.applyCustomLimits(Env);
cb(); cb();
}); });

@ -106,6 +106,7 @@ commands.SET_QUOTA = function (Env, args) {
throw new Error("INVALID_ARGS"); throw new Error("INVALID_ARGS");
} }
limit.origin = 'decree';
// map the new limit to the user's unsafeKey // map the new limit to the user's unsafeKey
Env.customLimits[unsafeKey] = limit; Env.customLimits[unsafeKey] = limit;
Env.limits[unsafeKey] = limit; Env.limits[unsafeKey] = limit;

@ -79,6 +79,15 @@ module.exports.create = function (config, cb) {
domain: config.domain domain: config.domain
}; };
(function () {
var custom = Env.customLimits;
for (var k in custom) {
if (k.length === 44 && custom[k]) {
custom.origin = 'config';
}
}
}());
(function () { (function () {
var pes = config.premiumUploadSize; var pes = config.premiumUploadSize;
if (!isNaN(pes) && pes >= Env.maxUploadSize) { if (!isNaN(pes) && pes >= Env.maxUploadSize) {

Loading…
Cancel
Save