implement GET_LIMITS admin rpc

...and label stored usage limits according to their source
This commit is contained in:
ansuz 2020-10-07 15:08:33 +05:30
parent 5029281a53
commit 928b7e3583
4 changed files with 24 additions and 1 deletions

View File

@ -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 = {
ACTIVE_SESSIONS: getActiveSessions,
ACTIVE_PADS: getActiveChannelCount,
@ -241,6 +246,7 @@ var commands = {
ADMIN_DECREE: adminDecree,
INSTANCE_STATUS: instanceStatus,
GET_LIMITS: getLimits,
};
Admin.command = function (Env, safeKey, data, _cb, Server) {

View File

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

View File

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

View File

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