From 46965bbb441923c1673ad1a0fdd53e7435a88595 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 20 Apr 2022 09:46:20 +0100 Subject: [PATCH] Feature flag upgrade page --- packages/builder/src/helpers/featureFlags.js | 14 ++++++++++++++ .../src/pages/builder/portal/_layout.svelte | 14 +++++++++----- packages/worker/src/api/controllers/global/self.js | 6 ++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 packages/builder/src/helpers/featureFlags.js diff --git a/packages/builder/src/helpers/featureFlags.js b/packages/builder/src/helpers/featureFlags.js new file mode 100644 index 0000000000..9533abed7e --- /dev/null +++ b/packages/builder/src/helpers/featureFlags.js @@ -0,0 +1,14 @@ +import { auth } from "../stores/portal" +import { get } from "svelte/store" + +export const FEATURE_FLAGS = { + LICENSING: "LICENSING", +} + +export const isEnabled = featureFlag => { + const user = get(auth).user + if (user?.featureFlags?.includes(featureFlag)) { + return true + } + return false +} diff --git a/packages/builder/src/pages/builder/portal/_layout.svelte b/packages/builder/src/pages/builder/portal/_layout.svelte index b527bd649b..495319a25e 100644 --- a/packages/builder/src/pages/builder/portal/_layout.svelte +++ b/packages/builder/src/pages/builder/portal/_layout.svelte @@ -20,6 +20,7 @@ import ChangePasswordModal from "components/settings/ChangePasswordModal.svelte" import UpdateAPIKeyModal from "components/settings/UpdateAPIKeyModal.svelte" import Logo from "assets/bb-emblem.svg" + import { isEnabled, FEATURE_FLAGS } from "../../../helpers/featureFlags" let loaded = false let userInfoModal @@ -54,15 +55,18 @@ if (!$adminStore.cloud) { menu = menu.concat([ { - title: "Updates", + title: "Update", href: "/builder/portal/settings/update", }, - { - title: "Upgrade", - href: "/builder/portal/settings/upgrade", - }, ]) } + + if (isEnabled(FEATURE_FLAGS.LICENSING)) { + menu = menu.concat({ + title: "Upgrade", + href: "/builder/portal/settings/upgrade", + }) + } } else { menu = menu.concat([ { diff --git a/packages/worker/src/api/controllers/global/self.js b/packages/worker/src/api/controllers/global/self.js index 935fc4259e..99346c1298 100644 --- a/packages/worker/src/api/controllers/global/self.js +++ b/packages/worker/src/api/controllers/global/self.js @@ -15,6 +15,7 @@ const { encrypt } = require("@budibase/backend-core/encryption") const { newid } = require("@budibase/backend-core/utils") const { getUser } = require("../../utilities") const { Cookies } = require("@budibase/backend-core/constants") +const { featureFlags } = require("@budibase/backend-core") function newApiKey() { return encrypt(`${getTenantId()}${SEPARATOR}${newid()}`) @@ -104,6 +105,11 @@ exports.getSelf = async ctx => { // get the main body of the user ctx.body = await getUser(userId) + + // add the feature flags for this tenant + const tenantId = getTenantId() + ctx.body.featureFlags = featureFlags.getTenantFeatureFlags(tenantId) + addSessionAttributesToUser(ctx) }