fallback SMTP configuration for cloud
This commit is contained in:
parent
3b49866825
commit
35d4eac78a
|
@ -546,7 +546,7 @@ module External {
|
|||
},
|
||||
meta: {
|
||||
table,
|
||||
}
|
||||
},
|
||||
}
|
||||
// can't really use response right now
|
||||
const response = await makeExternalQuery(appId, json)
|
||||
|
|
|
@ -13,8 +13,6 @@ const { makePartial } = require("../../tests/utilities")
|
|||
const { cleanInputValues } = require("../automationUtils")
|
||||
const setup = require("./utilities")
|
||||
|
||||
usageQuota.getAPIKey.mockReturnValue({ apiKey: "test" })
|
||||
|
||||
describe("Run through some parts of the automations system", () => {
|
||||
let config = setup.getConfig()
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ describe("test the create row action", () => {
|
|||
await setup.runStep(setup.actions.CREATE_ROW.stepId, {
|
||||
row
|
||||
})
|
||||
expect(usageQuota.update).toHaveBeenCalledWith(setup.apiKey, "rows", 1)
|
||||
expect(usageQuota.update).toHaveBeenCalledWith("rows", 1)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ describe("test the delete row action", () => {
|
|||
it("check usage quota attempts", async () => {
|
||||
await setup.runInProd(async () => {
|
||||
await setup.runStep(setup.actions.DELETE_ROW.stepId, inputs)
|
||||
expect(usageQuota.update).toHaveBeenCalledWith(setup.apiKey, "rows", -1)
|
||||
expect(usageQuota.update).toHaveBeenCalledWith("rows", -1)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {Table} from "./common";
|
||||
import { Table } from "./common"
|
||||
|
||||
export enum Operation {
|
||||
CREATE = "CREATE",
|
||||
|
@ -139,7 +139,7 @@ export interface QueryJson {
|
|||
paginate?: PaginationJson
|
||||
body?: object
|
||||
meta?: {
|
||||
table?: Table,
|
||||
table?: Table
|
||||
}
|
||||
extra?: {
|
||||
idFilter?: SearchFilters
|
||||
|
|
|
@ -252,9 +252,9 @@ module MySQLModule {
|
|||
json.extra = {
|
||||
idFilter: {
|
||||
equal: {
|
||||
[primaryKey]: results.insertId
|
||||
[primaryKey]: results.insertId,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
return json
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class TestConfiguration {
|
|||
if (bool) {
|
||||
env.isDev = () => false
|
||||
env.isProd = () => true
|
||||
this.ctx.auth = { apiKey: "test" }
|
||||
this.ctx.user = { tenantId: "test" }
|
||||
} else {
|
||||
env.isDev = () => true
|
||||
env.isProd = () => false
|
||||
|
@ -114,7 +114,7 @@ describe("usageQuota middleware", () => {
|
|||
|
||||
await config.executeMiddleware()
|
||||
|
||||
expect(usageQuota.update).toHaveBeenCalledWith("test", "rows", 1)
|
||||
expect(usageQuota.update).toHaveBeenCalledWith("rows", 1)
|
||||
expect(config.next).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
|
@ -131,7 +131,7 @@ describe("usageQuota middleware", () => {
|
|||
])
|
||||
await config.executeMiddleware()
|
||||
|
||||
expect(usageQuota.update).toHaveBeenCalledWith("test", "storage", 10100)
|
||||
expect(usageQuota.update).toHaveBeenCalledWith("storage", 10100)
|
||||
expect(config.next).toHaveBeenCalled()
|
||||
})
|
||||
})
|
|
@ -50,15 +50,15 @@ module.exports = async (ctx, next) => {
|
|||
}
|
||||
|
||||
// update usage for uploads to be the total size
|
||||
// if (property === usageQuota.Properties.UPLOAD) {
|
||||
// const files =
|
||||
// ctx.request.files.file.length > 1
|
||||
// ? Array.from(ctx.request.files.file)
|
||||
// : [ctx.request.files.file]
|
||||
// usage = files.map(file => file.size).reduce((total, size) => total + size)
|
||||
// }
|
||||
if (property === usageQuota.Properties.UPLOAD) {
|
||||
const files =
|
||||
ctx.request.files.file.length > 1
|
||||
? Array.from(ctx.request.files.file)
|
||||
: [ctx.request.files.file]
|
||||
usage = files.map(file => file.size).reduce((total, size) => total + size)
|
||||
}
|
||||
try {
|
||||
await usageQuota.update(ctx.user.tenantId, property, usage)
|
||||
await usageQuota.update(property, usage)
|
||||
return next()
|
||||
} catch (err) {
|
||||
ctx.throw(400, err)
|
||||
|
|
|
@ -12,6 +12,7 @@ exports.Properties = {
|
|||
USER: "users",
|
||||
AUTOMATION: "automationRuns",
|
||||
APPS: "apps",
|
||||
EMAILS: "emails",
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +29,8 @@ exports.update = async (property, usage) => {
|
|||
try {
|
||||
const db = getGlobalDB()
|
||||
const quota = await db.get("usage_quota")
|
||||
// TODO: check if the quota needs reset
|
||||
|
||||
// Check if the quota needs reset
|
||||
if (Date.now() >= quota.quotaReset) {
|
||||
quota.quotaReset = getNewQuotaReset()
|
||||
for (let prop of Object.keys(quota.usageQuota)) {
|
||||
|
|
|
@ -151,6 +151,7 @@ exports.adminUser = async ctx => {
|
|||
apps: 0,
|
||||
users: 0,
|
||||
views: 0,
|
||||
emails: 0,
|
||||
},
|
||||
usageLimits: {
|
||||
automationRuns: 1000,
|
||||
|
@ -158,6 +159,7 @@ exports.adminUser = async ctx => {
|
|||
apps: 4,
|
||||
storage: 1000,
|
||||
users: 10,
|
||||
emails: 50,
|
||||
},
|
||||
})
|
||||
// }
|
||||
|
|
|
@ -33,6 +33,11 @@ module.exports = {
|
|||
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
||||
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
||||
ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
|
||||
SMTP_USER: process.env.SMTP_USER,
|
||||
SMTP_PASSWORD: process.env.SMTP_PASSWORD,
|
||||
SMTP_HOST: process.env.SMTP_HOST,
|
||||
SMTP_PORT: process.env.SMTP_PORT,
|
||||
SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS,
|
||||
_set(key, value) {
|
||||
process.env[key] = value
|
||||
module.exports[key] = value
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const nodemailer = require("nodemailer")
|
||||
const env = require("../environment")
|
||||
const { getScopedConfig } = require("@budibase/auth/db")
|
||||
const { EmailTemplatePurpose, TemplateTypes, Configs } = require("../constants")
|
||||
const { getTemplateByPurpose } = require("../constants/templates")
|
||||
|
@ -110,7 +111,21 @@ async function getSmtpConfiguration(db, workspaceId = null) {
|
|||
if (workspaceId) {
|
||||
params.workspace = workspaceId
|
||||
}
|
||||
|
||||
if (!env.SMTP_FALLBACK_ENABLED) {
|
||||
return getScopedConfig(db, params)
|
||||
} else {
|
||||
// Use an SMTP fallback configuration from env variables
|
||||
return {
|
||||
port: env.SMTP_PORT,
|
||||
host: env.SMTP_HOST,
|
||||
secure: false,
|
||||
auth: {
|
||||
user: env.SMTP_USER,
|
||||
pass: env.SMTP_PASSWORD,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,8 +133,8 @@ async function getSmtpConfiguration(db, workspaceId = null) {
|
|||
* @return {Promise<boolean>} returns true if there is a configuration that can be used.
|
||||
*/
|
||||
exports.isEmailConfigured = async (workspaceId = null) => {
|
||||
// when "testing" simply return true
|
||||
if (TEST_MODE) {
|
||||
// when "testing" or smtp fallback is enabled simply return true
|
||||
if (TEST_MODE || env.SMTP_FALLBACK_ENABLED) {
|
||||
return true
|
||||
}
|
||||
const db = getGlobalDB()
|
||||
|
|
Loading…
Reference in New Issue