Skip to content

Commit

Permalink
Merge pull request #10922 from Budibase/fix/budi-7069
Browse files Browse the repository at this point in the history
Fix public apps still displaying free footer when licensed
  • Loading branch information
mike12345567 committed Jun 15, 2023
2 parents 7531a16 + ebc3a6d commit d0b442f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
20 changes: 16 additions & 4 deletions packages/client/src/licensing/utils.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 24 additions & 21 deletions packages/server/src/api/controllers/application.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit d0b442f

Please sign in to comment.