Move branding read behind pro

This commit is contained in:
Rory Powell 2023-03-27 22:28:25 +01:00
parent 4de8333f80
commit 60650b031b
4 changed files with 31 additions and 48 deletions

View File

@ -15,6 +15,7 @@ import { context, objectStore, utils, configs } from "@budibase/backend-core"
import AWS from "aws-sdk" import AWS from "aws-sdk"
import fs from "fs" import fs from "fs"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import * as pro from "@budibase/pro"
const send = require("koa-send") const send = require("koa-send")
@ -101,6 +102,8 @@ export const deleteObjects = async function (ctx: any) {
export const serveApp = async function (ctx: any) { export const serveApp = async function (ctx: any) {
//Public Settings //Public Settings
const { config } = await configs.getSettingsConfigDoc() const { config } = await configs.getSettingsConfigDoc()
const branding = await pro.branding.getBrandingConfig(config)
let db let db
try { try {
db = context.getAppDB({ skip_setup: true }) db = context.getAppDB({ skip_setup: true })
@ -112,17 +115,17 @@ export const serveApp = async function (ctx: any) {
const plugins = objectStore.enrichPluginURLs(appInfo.usedPlugins) const plugins = objectStore.enrichPluginURLs(appInfo.usedPlugins)
const { head, html, css } = App.render({ const { head, html, css } = App.render({
metaImage: metaImage:
config?.metaImageUrl || branding?.metaImageUrl ||
"https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png", "https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png",
metaDescription: config?.metaDescription || "", metaDescription: branding?.metaDescription || "",
metaTitle: config?.metaTitle || `${appInfo.name} - built with Budibase`, metaTitle: branding?.metaTitle || `${appInfo.name} - built with Budibase`,
title: appInfo.name, title: appInfo.name,
production: env.isProd(), production: env.isProd(),
appId, appId,
clientLibPath: objectStore.clientLibraryUrl(appId!, appInfo.version), clientLibPath: objectStore.clientLibraryUrl(appId!, appInfo.version),
usedPlugins: plugins, usedPlugins: plugins,
favicon: favicon:
config.faviconUrl !== "" branding.faviconUrl !== ""
? objectStore.getGlobalFileUrl("settings", "faviconUrl") ? objectStore.getGlobalFileUrl("settings", "faviconUrl")
: "", : "",
logo: logo:
@ -145,14 +148,14 @@ export const serveApp = async function (ctx: any) {
if (!env.isJest()) { if (!env.isJest()) {
const App = require("./templates/BudibaseApp.svelte").default const App = require("./templates/BudibaseApp.svelte").default
const { head, html, css } = App.render({ const { head, html, css } = App.render({
title: config?.metaTitle, title: branding?.metaTitle,
metaTitle: config?.metaTitle, metaTitle: branding?.metaTitle,
metaImage: metaImage:
config?.metaImageUrl || branding?.metaImageUrl ||
"https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png", "https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png",
metaDescription: config?.metaDescription || "", metaDescription: branding?.metaDescription || "",
favicon: favicon:
config.faviconUrl !== "" branding.faviconUrl !== ""
? objectStore.getGlobalFileUrl("settings", "faviconUrl") ? objectStore.getGlobalFileUrl("settings", "faviconUrl")
: "", : "",
}) })

View File

@ -22,12 +22,10 @@ export interface SMTPConfig extends Config {
config: SMTPInnerConfig config: SMTPInnerConfig
} }
export interface SettingsInnerConfig { /**
platformUrl?: string * Accessible only via pro.
company?: string */
logoUrl?: string // Populated on read export interface SettingsBrandingConfig {
logoUrlEtag?: string
faviconUrl?: string faviconUrl?: string
faviconUrlEtag?: string faviconUrlEtag?: string
@ -40,7 +38,13 @@ export interface SettingsInnerConfig {
metaDescription?: string metaDescription?: string
metaImageUrl?: string metaImageUrl?: string
metaTitle?: string metaTitle?: string
}
export interface SettingsInnerConfig {
platformUrl?: string
company?: string
logoUrl?: string // Populated on read
logoUrlEtag?: string
uniqueTenantId?: string uniqueTenantId?: string
analyticsEnabled?: boolean analyticsEnabled?: boolean
isSSOEnforced?: boolean isSSOEnforced?: boolean

View File

@ -15,7 +15,6 @@ import {
Config, Config,
ConfigType, ConfigType,
Ctx, Ctx,
Feature,
GetPublicOIDCConfigResponse, GetPublicOIDCConfigResponse,
GetPublicSettingsResponse, GetPublicSettingsResponse,
GoogleInnerConfig, GoogleInnerConfig,
@ -30,7 +29,6 @@ import {
UserCtx, UserCtx,
} from "@budibase/types" } from "@budibase/types"
import * as pro from "@budibase/pro" import * as pro from "@budibase/pro"
import { licensing } from "@budibase/pro"
const getEventFns = async (config: Config, existing?: Config) => { const getEventFns = async (config: Config, existing?: Config) => {
const fns = [] const fns = []
@ -271,31 +269,6 @@ export async function publicOidc(ctx: Ctx<void, GetPublicOIDCConfigResponse>) {
} }
} }
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( export async function publicSettings(
ctx: Ctx<void, GetPublicSettingsResponse> ctx: Ctx<void, GetPublicSettingsResponse>
) { ) {
@ -304,7 +277,7 @@ export async function publicSettings(
const configDoc = await configs.getSettingsConfigDoc() const configDoc = await configs.getSettingsConfigDoc()
const config = configDoc.config const config = configDoc.config
const licensedConfig: object = await getLicensedConfig() const branding = await pro.branding.getBrandingConfig(config)
// enrich the logo url - empty url means deleted // enrich the logo url - empty url means deleted
if (config.logoUrl && config.logoUrl !== "") { 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( config.faviconUrl = objectStore.getGlobalFileUrl(
"settings", "settings",
"faviconUrl", "faviconUrl",
config.faviconUrl branding.faviconUrl
) )
} }
@ -343,7 +317,7 @@ export async function publicSettings(
_rev: configDoc._rev, _rev: configDoc._rev,
config: { config: {
...config, ...config,
...licensedConfig, ...branding,
google, google,
oidc, oidc,
isSSOEnforced, isSSOEnforced,

View File

@ -6,12 +6,14 @@ import {
} from "../constants" } from "../constants"
import { checkSlashesInUrl } from "./index" import { checkSlashesInUrl } from "./index"
const BASE_COMPANY = "Budibase" const BASE_COMPANY = "Budibase"
import * as pro from "@budibase/pro"
export async function getSettingsTemplateContext( export async function getSettingsTemplateContext(
purpose: EmailTemplatePurpose, purpose: EmailTemplatePurpose,
code?: string | null 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 URL = settings.platformUrl
const context: any = { const context: any = {
[InternalTemplateBinding.LOGO_URL]: [InternalTemplateBinding.LOGO_URL]:
@ -26,7 +28,7 @@ export async function getSettingsTemplateContext(
[InternalTemplateBinding.CURRENT_YEAR]: new Date().getFullYear(), [InternalTemplateBinding.CURRENT_YEAR]: new Date().getFullYear(),
} }
context["enableEmailBranding"] = settings.emailBrandingEnabled === true context["enableEmailBranding"] = branding.emailBrandingEnabled === true
// attach purpose specific context // attach purpose specific context
switch (purpose) { switch (purpose) {