From 67e2ce86ce14521a025c2ec115bf2128fad2873a Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 15 Jun 2023 16:33:07 +0100 Subject: [PATCH 1/2] Adding a license mechanism to the app package call so that public apps can still return what license the app utilises. This is retrieved based on the tenant of the app - we only attach the license type so as to not expose further information than is necessary. --- packages/client/src/licensing/utils.js | 20 +++++++-- .../server/src/api/controllers/application.ts | 45 ++++++++++--------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/packages/client/src/licensing/utils.js b/packages/client/src/licensing/utils.js index effed6867f..544fa0f526 100644 --- a/packages/client/src/licensing/utils.js +++ b/packages/client/src/licensing/utils.js @@ -1,18 +1,30 @@ import { authStore } from "../stores/auth.js" +import { appStore } from "../stores/app.js" import { get } from "svelte/store" import { Constants } from "@budibase/frontend-core" -const getLicense = () => { +const getUserLicense = () => { const user = get(authStore) if (user) { return user.license } } +const getAppLicenseType = () => { + const appDef = get(appStore) + if (appDef?.licenseType) { + return appDef.licenseType + } +} + export const isFreePlan = () => { - const license = getLicense() - if (license) { - return license.plan.type === Constants.PlanType.FREE + let licenseType = getAppLicenseType() + if (!licenseType) { + const license = getUserLicense() + licenseType = license?.plan?.type + } + if (licenseType) { + return licenseType === Constants.PlanType.FREE } else { // safety net - no license means free plan return true diff --git a/packages/server/src/api/controllers/application.ts b/packages/server/src/api/controllers/application.ts index 9c89b48b8a..ed31615981 100644 --- a/packages/server/src/api/controllers/application.ts +++ b/packages/server/src/api/controllers/application.ts @@ -1,53 +1,54 @@ import env from "../../environment" import { + createAllSearchIndex, createLinkView, createRoutingView, - createAllSearchIndex, } from "../../db/views/staticViews" -import { createApp, deleteApp } from "../../utilities/fileSystem" import { + backupClientLibrary, + createApp, + deleteApp, + revertClientLibrary, + updateClientLibrary, +} from "../../utilities/fileSystem" +import { + AppStatus, + DocumentType, generateAppID, + generateDevAppID, getLayoutParams, getScreenParams, - generateDevAppID, - DocumentType, - AppStatus, } from "../../db/utils" import { - db as dbCore, - roles, cache, - tenancy, context, + db as dbCore, + env as envCore, + ErrorCode, events, migrations, objectStore, - ErrorCode, - env as envCore, + roles, + tenancy, } from "@budibase/backend-core" import { USERS_TABLE_SCHEMA } from "../../constants" import { - DEFAULT_BB_DATASOURCE_ID, buildDefaultDocs, + DEFAULT_BB_DATASOURCE_ID, } from "../../db/defaultData/datasource_bb_default" import { removeAppFromUserRoles } from "../../utilities/workerRequests" -import { stringToReadStream, isQsTrue } from "../../utilities" -import { getLocksById, doesUserHaveLock } from "../../utilities/redis" -import { - updateClientLibrary, - backupClientLibrary, - revertClientLibrary, -} from "../../utilities/fileSystem" +import { stringToReadStream } from "../../utilities" +import { doesUserHaveLock, getLocksById } from "../../utilities/redis" import { cleanupAutomations } from "../../automations/utils" import { checkAppMetadata } from "../../automations/logging" import { getUniqueRows } from "../../utilities/usageQuota/rows" -import { quotas, groups } from "@budibase/pro" +import { groups, licensing, quotas } from "@budibase/pro" import { App, Layout, - Screen, MigrationType, - Database, + PlanType, + Screen, UserCtx, } from "@budibase/types" import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts" @@ -207,6 +208,7 @@ export async function fetchAppPackage(ctx: UserCtx) { let application = await db.get(DocumentType.APP_METADATA) const layouts = await getLayouts() let screens = await getScreens() + const license = await licensing.getLicense() // Enrich plugin URLs application.usedPlugins = objectStore.enrichPluginURLs( @@ -227,6 +229,7 @@ export async function fetchAppPackage(ctx: UserCtx) { ctx.body = { application: { ...application, upgradableVersion: envCore.VERSION }, + licenseType: license?.plan.type || PlanType.FREE, screens, layouts, clientLibPath, From a1c9aaf76009962ca6abcb6fe653a9459d34c4c0 Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Thu, 15 Jun 2023 15:53:18 +0000 Subject: [PATCH 2/2] Bump version to 2.7.20 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index a934df1b65..2494a5f30c 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.7.19", + "version": "2.7.20", "npmClient": "yarn", "packages": [ "packages/backend-core",