From 4de8333f80899ed828c1d79bf5a81c073d857a65 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 27 Mar 2023 18:00:57 +0100 Subject: [PATCH] Review updates --- .../src/api/controllers/global/configs.ts | 38 +++++++++++++------ .../api/routes/global/tests/configs.spec.ts | 2 + packages/worker/src/utilities/email.ts | 2 +- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/packages/worker/src/api/controllers/global/configs.ts b/packages/worker/src/api/controllers/global/configs.ts index e17442eb79..d77b9c81d5 100644 --- a/packages/worker/src/api/controllers/global/configs.ts +++ b/packages/worker/src/api/controllers/global/configs.ts @@ -271,6 +271,31 @@ export async function publicOidc(ctx: Ctx) { } } +export async function getLicensedConfig() { + let licensedConfig: object = {} + const defaults = { + emailBrandingEnabled: true, + testimonialsEnabled: true, + platformTitle: undefined, + metaDescription: undefined, + metaImageUrl: undefined, + metaTitle: undefined, + } + + try { + // License/Feature Checks + const license = await licensing.getLicense() + + if (!license || license?.features.indexOf(Feature.BRANDING) == -1) { + licensedConfig = { ...defaults } + } + } catch (e) { + licensedConfig = { ...defaults } + console.info("Could not retrieve license", e) + } + return licensedConfig +} + export async function publicSettings( ctx: Ctx ) { @@ -279,18 +304,7 @@ export async function publicSettings( const configDoc = await configs.getSettingsConfigDoc() const config = configDoc.config - // License/Feature Checks - const license = await licensing.getLicense() - - const licensedConfig: any = {} - if (!license || license?.features.indexOf(Feature.BRANDING) == -1) { - licensedConfig["emailBrandingEnabled"] = true - licensedConfig["testimonialsEnabled"] = true - licensedConfig["platformTitle"] = undefined - licensedConfig["metaDescription"] = undefined - licensedConfig["metaImageUrl"] = undefined - licensedConfig["metaTitle"] = undefined - } + const licensedConfig: object = await getLicensedConfig() // enrich the logo url - empty url means deleted if (config.logoUrl && config.logoUrl !== "") { diff --git a/packages/worker/src/api/routes/global/tests/configs.spec.ts b/packages/worker/src/api/routes/global/tests/configs.spec.ts index 1abe575b02..8c31adff2b 100644 --- a/packages/worker/src/api/routes/global/tests/configs.spec.ts +++ b/packages/worker/src/api/routes/global/tests/configs.spec.ts @@ -286,6 +286,7 @@ describe("configs", () => { type: "settings", config: { company: "Budibase", + emailBrandingEnabled: true, logoUrl: "", analyticsEnabled: false, google: false, @@ -294,6 +295,7 @@ describe("configs", () => { oidc: false, oidcCallbackUrl: `http://localhost:10000/api/global/auth/${config.tenantId}/oidc/callback`, platformUrl: "http://localhost:10000", + testimonialsEnabled: true, }, } delete body._rev diff --git a/packages/worker/src/utilities/email.ts b/packages/worker/src/utilities/email.ts index 192126907b..fcd022cd92 100644 --- a/packages/worker/src/utilities/email.ts +++ b/packages/worker/src/utilities/email.ts @@ -111,7 +111,7 @@ async function buildEmail( ]) // Change from branding to core - let core = EmailTemplates.core + let core = EmailTemplates[EmailTemplatePurpose.CORE] if (!base || !body || !core) { throw "Unable to build email, missing base components"