From 757fbbc19c3150b1576233d6d1e1eace04769fff Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 27 Sep 2021 15:03:48 +0100 Subject: [PATCH] re-adding env var controls for cloud limit functionality --- packages/server/src/middleware/usageQuota.js | 8 ++-- packages/server/src/utilities/usageQuota.js | 9 ++-- .../src/api/controllers/global/users.js | 48 +++++++++---------- packages/worker/src/utilities/email.js | 6 ++- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/packages/server/src/middleware/usageQuota.js b/packages/server/src/middleware/usageQuota.js index d56a960615..3a244ef5bc 100644 --- a/packages/server/src/middleware/usageQuota.js +++ b/packages/server/src/middleware/usageQuota.js @@ -1,6 +1,6 @@ const CouchDB = require("../db") const usageQuota = require("../utilities/usageQuota") -// const env = require("../environment") +const env = require("../environment") // currently only counting new writes and deletes const METHOD_MAP = { @@ -29,9 +29,9 @@ function getProperty(url) { module.exports = async (ctx, next) => { // if in development or a self hosted cloud usage quotas should not be executed - // if (env.isDev() || env.SELF_HOSTED) { - // return next() - // } + if (env.isDev() || env.SELF_HOSTED) { + return next() + } const db = new CouchDB(ctx.appId) let usage = METHOD_MAP[ctx.req.method] diff --git a/packages/server/src/utilities/usageQuota.js b/packages/server/src/utilities/usageQuota.js index fb3f61f2f6..4e645ec67d 100644 --- a/packages/server/src/utilities/usageQuota.js +++ b/packages/server/src/utilities/usageQuota.js @@ -1,4 +1,4 @@ -// const env = require("../environment") +const env = require("../environment") const { getGlobalDB } = require("@budibase/auth/tenancy") function getNewQuotaReset() { @@ -23,9 +23,10 @@ exports.Properties = { * also been reset after this call. */ exports.update = async (property, usage) => { - // if (!env.USE_QUOTAS) { - // return - // } + if (!env.USE_QUOTAS) { + return + } + try { const db = getGlobalDB() const quota = await db.get("usage_quota") diff --git a/packages/worker/src/api/controllers/global/users.js b/packages/worker/src/api/controllers/global/users.js index c714f2b1ca..e00fd3ecc0 100644 --- a/packages/worker/src/api/controllers/global/users.js +++ b/packages/worker/src/api/controllers/global/users.js @@ -17,7 +17,7 @@ const { tryAddTenant, updateTenantId, } = require("@budibase/auth/tenancy") -// const env = require("../../../environment") +const env = require("../../../environment") const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name @@ -140,29 +140,29 @@ exports.adminUser = async ctx => { ) // write usage quotas for cloud - // if (!env.SELF_HOSTED) { - await db.post({ - _id: "usage_quota", - quotaReset: Date.now() + 2592000000, - usageQuota: { - automationRuns: 0, - rows: 0, - storage: 0, - apps: 0, - users: 0, - views: 0, - emails: 0, - }, - usageLimits: { - automationRuns: 1000, - rows: 4000, - apps: 4, - storage: 1000, - users: 10, - emails: 50, - }, - }) - // } + if (!env.SELF_HOSTED) { + await db.post({ + _id: "usage_quota", + quotaReset: Date.now() + 2592000000, + usageQuota: { + automationRuns: 0, + rows: 0, + storage: 0, + apps: 0, + users: 0, + views: 0, + emails: 0, + }, + usageLimits: { + automationRuns: 1000, + rows: 4000, + apps: 4, + storage: 1000, + users: 10, + emails: 50, + }, + }) + } if (response.rows.some(row => row.doc.admin)) { ctx.throw( diff --git a/packages/worker/src/utilities/email.js b/packages/worker/src/utilities/email.js index 5843cb28ea..cd29170348 100644 --- a/packages/worker/src/utilities/email.js +++ b/packages/worker/src/utilities/email.js @@ -112,8 +112,10 @@ async function getSmtpConfiguration(db, workspaceId = null) { params.workspace = workspaceId } - if (!env.SMTP_FALLBACK_ENABLED) { - return getScopedConfig(db, params) + const customConfig = getScopedConfig(db, params) + + if (customConfig && !env.SMTP_FALLBACK_ENABLED) { + return customConfig } else { // Use an SMTP fallback configuration from env variables return {