Move branding read behind pro
This commit is contained in:
parent
4de8333f80
commit
60650b031b
|
@ -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")
|
||||
: "",
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<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(
|
||||
ctx: Ctx<void, GetPublicSettingsResponse>
|
||||
) {
|
||||
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue