From 60650b031b8b183f0757f876e9d3e46c9c4d655d Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Mon, 27 Mar 2023 22:28:25 +0100 Subject: [PATCH 1/2] Move branding read behind pro --- .../src/api/controllers/static/index.ts | 21 ++++++----- packages/types/src/documents/global/config.ts | 16 +++++---- .../src/api/controllers/global/configs.ts | 36 +++---------------- packages/worker/src/utilities/templates.ts | 6 ++-- 4 files changed, 31 insertions(+), 48 deletions(-) diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index 21dcce6610..c46c14bed3 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -15,6 +15,7 @@ import { context, objectStore, utils, configs } from "@budibase/backend-core" import AWS from "aws-sdk" import fs from "fs" import sdk from "../../../sdk" +import * as pro from "@budibase/pro" const send = require("koa-send") @@ -101,6 +102,8 @@ export const deleteObjects = async function (ctx: any) { export const serveApp = async function (ctx: any) { //Public Settings const { config } = await configs.getSettingsConfigDoc() + const branding = await pro.branding.getBrandingConfig(config) + let db try { db = context.getAppDB({ skip_setup: true }) @@ -112,17 +115,17 @@ export const serveApp = async function (ctx: any) { const plugins = objectStore.enrichPluginURLs(appInfo.usedPlugins) const { head, html, css } = App.render({ metaImage: - config?.metaImageUrl || + branding?.metaImageUrl || "https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png", - metaDescription: config?.metaDescription || "", - metaTitle: config?.metaTitle || `${appInfo.name} - built with Budibase`, + metaDescription: branding?.metaDescription || "", + metaTitle: branding?.metaTitle || `${appInfo.name} - built with Budibase`, title: appInfo.name, production: env.isProd(), appId, clientLibPath: objectStore.clientLibraryUrl(appId!, appInfo.version), usedPlugins: plugins, favicon: - config.faviconUrl !== "" + branding.faviconUrl !== "" ? objectStore.getGlobalFileUrl("settings", "faviconUrl") : "", logo: @@ -145,14 +148,14 @@ export const serveApp = async function (ctx: any) { if (!env.isJest()) { const App = require("./templates/BudibaseApp.svelte").default const { head, html, css } = App.render({ - title: config?.metaTitle, - metaTitle: config?.metaTitle, + title: branding?.metaTitle, + metaTitle: branding?.metaTitle, metaImage: - config?.metaImageUrl || + branding?.metaImageUrl || "https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png", - metaDescription: config?.metaDescription || "", + metaDescription: branding?.metaDescription || "", favicon: - config.faviconUrl !== "" + branding.faviconUrl !== "" ? objectStore.getGlobalFileUrl("settings", "faviconUrl") : "", }) diff --git a/packages/types/src/documents/global/config.ts b/packages/types/src/documents/global/config.ts index d1e7eac39b..f2e266a5e2 100644 --- a/packages/types/src/documents/global/config.ts +++ b/packages/types/src/documents/global/config.ts @@ -22,12 +22,10 @@ export interface SMTPConfig extends Config { config: SMTPInnerConfig } -export interface SettingsInnerConfig { - platformUrl?: string - company?: string - logoUrl?: string // Populated on read - logoUrlEtag?: string - +/** + * Accessible only via pro. + */ +export interface SettingsBrandingConfig { faviconUrl?: string faviconUrlEtag?: string @@ -40,7 +38,13 @@ export interface SettingsInnerConfig { metaDescription?: string metaImageUrl?: string metaTitle?: string +} +export interface SettingsInnerConfig { + platformUrl?: string + company?: string + logoUrl?: string // Populated on read + logoUrlEtag?: string uniqueTenantId?: string analyticsEnabled?: boolean isSSOEnforced?: boolean diff --git a/packages/worker/src/api/controllers/global/configs.ts b/packages/worker/src/api/controllers/global/configs.ts index d77b9c81d5..1d666ca93d 100644 --- a/packages/worker/src/api/controllers/global/configs.ts +++ b/packages/worker/src/api/controllers/global/configs.ts @@ -15,7 +15,6 @@ import { Config, ConfigType, Ctx, - Feature, GetPublicOIDCConfigResponse, GetPublicSettingsResponse, GoogleInnerConfig, @@ -30,7 +29,6 @@ import { UserCtx, } from "@budibase/types" import * as pro from "@budibase/pro" -import { licensing } from "@budibase/pro" const getEventFns = async (config: Config, existing?: Config) => { const fns = [] @@ -271,31 +269,6 @@ 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 ) { @@ -304,7 +277,7 @@ export async function publicSettings( const configDoc = await configs.getSettingsConfigDoc() const config = configDoc.config - const licensedConfig: object = await getLicensedConfig() + const branding = await pro.branding.getBrandingConfig(config) // enrich the logo url - empty url means deleted if (config.logoUrl && config.logoUrl !== "") { @@ -315,11 +288,12 @@ export async function publicSettings( ) } - if (config.faviconUrl && config.faviconUrl !== "") { + if (branding.faviconUrl && branding.faviconUrl !== "") { + // @ts-ignore config.faviconUrl = objectStore.getGlobalFileUrl( "settings", "faviconUrl", - config.faviconUrl + branding.faviconUrl ) } @@ -343,7 +317,7 @@ export async function publicSettings( _rev: configDoc._rev, config: { ...config, - ...licensedConfig, + ...branding, google, oidc, isSSOEnforced, diff --git a/packages/worker/src/utilities/templates.ts b/packages/worker/src/utilities/templates.ts index d311ab7ba6..adc18831db 100644 --- a/packages/worker/src/utilities/templates.ts +++ b/packages/worker/src/utilities/templates.ts @@ -6,12 +6,14 @@ import { } from "../constants" import { checkSlashesInUrl } from "./index" const BASE_COMPANY = "Budibase" +import * as pro from "@budibase/pro" export async function getSettingsTemplateContext( purpose: EmailTemplatePurpose, code?: string | null ) { - let settings = await configs.getSettingsConfig() + const settings = await configs.getSettingsConfig() + const branding = await pro.branding.getBrandingConfig(settings) const URL = settings.platformUrl const context: any = { [InternalTemplateBinding.LOGO_URL]: @@ -26,7 +28,7 @@ export async function getSettingsTemplateContext( [InternalTemplateBinding.CURRENT_YEAR]: new Date().getFullYear(), } - context["enableEmailBranding"] = settings.emailBrandingEnabled === true + context["enableEmailBranding"] = branding.emailBrandingEnabled === true // attach purpose specific context switch (purpose) { From cd3b2ba199978f9cabef266197a78b2a88b5c78a Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Mon, 27 Mar 2023 22:39:35 +0100 Subject: [PATCH 2/2] Lint --- packages/client/yarn.lock | 5 ----- packages/server/src/api/controllers/static/index.ts | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/client/yarn.lock b/packages/client/yarn.lock index 189c93c120..e7140f7af3 100644 --- a/packages/client/yarn.lock +++ b/packages/client/yarn.lock @@ -23,11 +23,6 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@budibase/types@2.4.8-alpha.4": - version "2.4.8-alpha.4" - resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.4.8-alpha.4.tgz#4e6dec50eef381994432ef4d08587a9a7156dd84" - integrity sha512-aiHHOvsDLHQ2OFmLgaSUttQwSuaPBqF1lbyyCkEJIbbl/qo9EPNZGl+AkB7wo12U5HdqWhr9OpFL12EqkcD4GA== - "@jridgewell/gen-mapping@^0.3.0": version "0.3.2" resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz#c1aedc61e853f2bb9f5dfe6d4442d3b565b253b9" diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index c46c14bed3..c19fd1bb05 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -118,7 +118,8 @@ export const serveApp = async function (ctx: any) { branding?.metaImageUrl || "https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png", metaDescription: branding?.metaDescription || "", - metaTitle: branding?.metaTitle || `${appInfo.name} - built with Budibase`, + metaTitle: + branding?.metaTitle || `${appInfo.name} - built with Budibase`, title: appInfo.name, production: env.isProd(), appId,