Added feature flag function for branding to ensure it uses the cached license
This commit is contained in:
parent
4de8333f80
commit
56e1d102fc
|
@ -11,11 +11,11 @@ import {
|
||||||
tenancy,
|
tenancy,
|
||||||
} from "@budibase/backend-core"
|
} from "@budibase/backend-core"
|
||||||
import { checkAnyUserExists } from "../../../utilities/users"
|
import { checkAnyUserExists } from "../../../utilities/users"
|
||||||
|
import { getLicensedConfig } from "../../../utilities/configs"
|
||||||
import {
|
import {
|
||||||
Config,
|
Config,
|
||||||
ConfigType,
|
ConfigType,
|
||||||
Ctx,
|
Ctx,
|
||||||
Feature,
|
|
||||||
GetPublicOIDCConfigResponse,
|
GetPublicOIDCConfigResponse,
|
||||||
GetPublicSettingsResponse,
|
GetPublicSettingsResponse,
|
||||||
GoogleInnerConfig,
|
GoogleInnerConfig,
|
||||||
|
@ -30,7 +30,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 = []
|
||||||
|
@ -213,6 +212,38 @@ export async function save(ctx: UserCtx<Config>) {
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore branding changes if the license does not permit it
|
||||||
|
// Favicon and Logo Url are excluded.
|
||||||
|
try {
|
||||||
|
const brandingEnabled = await pro.features.isBrandingEnabled()
|
||||||
|
if (existingConfig?.config && !brandingEnabled) {
|
||||||
|
const {
|
||||||
|
emailBrandingEnabled,
|
||||||
|
testimonialsEnabled,
|
||||||
|
platformTitle,
|
||||||
|
metaDescription,
|
||||||
|
loginHeading,
|
||||||
|
loginButton,
|
||||||
|
metaImageUrl,
|
||||||
|
metaTitle,
|
||||||
|
} = existingConfig.config
|
||||||
|
|
||||||
|
body.config = {
|
||||||
|
...body.config,
|
||||||
|
emailBrandingEnabled,
|
||||||
|
testimonialsEnabled,
|
||||||
|
platformTitle,
|
||||||
|
metaDescription,
|
||||||
|
loginHeading,
|
||||||
|
loginButton,
|
||||||
|
metaImageUrl,
|
||||||
|
metaTitle,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("There was an issue retrieving the license", e)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
body._id = configs.generateConfigID(type)
|
body._id = configs.generateConfigID(type)
|
||||||
const response = await configs.save(body)
|
const response = await configs.save(body)
|
||||||
|
@ -271,31 +302,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>
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
import * as pro from "@budibase/pro"
|
||||||
|
|
||||||
|
export async function getLicensedConfig() {
|
||||||
|
let licensedConfig: object = {}
|
||||||
|
const defaults = {
|
||||||
|
emailBrandingEnabled: true,
|
||||||
|
testimonialsEnabled: true,
|
||||||
|
platformTitle: undefined,
|
||||||
|
metaDescription: undefined,
|
||||||
|
loginHeading: undefined,
|
||||||
|
loginButton: undefined,
|
||||||
|
metaImageUrl: undefined,
|
||||||
|
metaTitle: undefined,
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// License/Feature Checks
|
||||||
|
const enabled = await pro.features.isBrandingEnabled()
|
||||||
|
if (!enabled) {
|
||||||
|
licensedConfig = { ...defaults }
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
licensedConfig = { ...defaults }
|
||||||
|
console.info("Could not retrieve license", e)
|
||||||
|
}
|
||||||
|
return licensedConfig
|
||||||
|
}
|
|
@ -1,10 +1,13 @@
|
||||||
import { tenancy, configs } from "@budibase/backend-core"
|
import { tenancy, configs } from "@budibase/backend-core"
|
||||||
|
import { SettingsInnerConfig } from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
InternalTemplateBinding,
|
InternalTemplateBinding,
|
||||||
LOGO_URL,
|
LOGO_URL,
|
||||||
EmailTemplatePurpose,
|
EmailTemplatePurpose,
|
||||||
} from "../constants"
|
} from "../constants"
|
||||||
import { checkSlashesInUrl } from "./index"
|
import { checkSlashesInUrl } from "./index"
|
||||||
|
import { getLicensedConfig } from "./configs"
|
||||||
|
|
||||||
const BASE_COMPANY = "Budibase"
|
const BASE_COMPANY = "Budibase"
|
||||||
|
|
||||||
export async function getSettingsTemplateContext(
|
export async function getSettingsTemplateContext(
|
||||||
|
@ -26,7 +29,12 @@ export async function getSettingsTemplateContext(
|
||||||
[InternalTemplateBinding.CURRENT_YEAR]: new Date().getFullYear(),
|
[InternalTemplateBinding.CURRENT_YEAR]: new Date().getFullYear(),
|
||||||
}
|
}
|
||||||
|
|
||||||
context["enableEmailBranding"] = settings.emailBrandingEnabled === true
|
try {
|
||||||
|
const config: SettingsInnerConfig = await getLicensedConfig()
|
||||||
|
context["enableEmailBranding"] = config?.emailBrandingEnabled || true
|
||||||
|
} catch (e) {
|
||||||
|
context["enableEmailBranding"] = true
|
||||||
|
}
|
||||||
|
|
||||||
// attach purpose specific context
|
// attach purpose specific context
|
||||||
switch (purpose) {
|
switch (purpose) {
|
||||||
|
|
Loading…
Reference in New Issue