From a268e5560718e317180f8da7c71667b218c59cc1 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 30 Jan 2024 17:31:11 +0000 Subject: [PATCH 01/10] Plumbing for showing a maintenance page when SQS is required but missing. --- .../builder/src/pages/builder/_layout.svelte | 4 +++ .../pages/builder/maintenance/index.svelte | 27 +++++++++++++++++++ .../portal/_components/BudibaseLogo.svelte | 13 +++++++++ packages/builder/src/stores/portal/admin.js | 2 ++ packages/types/src/core/installation.ts | 4 +++ .../src/api/controllers/system/environment.ts | 19 ++++++++++--- .../routes/system/tests/environment.spec.ts | 4 +-- 7 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 packages/builder/src/pages/builder/maintenance/index.svelte create mode 100644 packages/builder/src/pages/builder/portal/_components/BudibaseLogo.svelte diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index 62d3951fb5..95ca05b87b 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -71,6 +71,10 @@ await auth.getSelf() await admin.init() + if ($admin.maintenance.length > 0) { + $redirect("./maintenance") + } + if ($auth.user) { await licensing.init() } diff --git a/packages/builder/src/pages/builder/maintenance/index.svelte b/packages/builder/src/pages/builder/maintenance/index.svelte new file mode 100644 index 0000000000..bdadd98c42 --- /dev/null +++ b/packages/builder/src/pages/builder/maintenance/index.svelte @@ -0,0 +1,27 @@ + + +{#each $admin.maintenance as maintenance} + {#if maintenance.type === MaintenanceType.SQS_MISSING} + + + + Please upgrade your Budibase installation + + We've detected that the version of Budibase you're using depends on a + more recent version of the CouchDB database than what you have + installed. + + + To resolve this, you can either rollback to a previous version of + Budibase, or follow the migration guide here + to update to a later version of CouchDB. + + + + {/if} +{/each} diff --git a/packages/builder/src/pages/builder/portal/_components/BudibaseLogo.svelte b/packages/builder/src/pages/builder/portal/_components/BudibaseLogo.svelte new file mode 100644 index 0000000000..8276510201 --- /dev/null +++ b/packages/builder/src/pages/builder/portal/_components/BudibaseLogo.svelte @@ -0,0 +1,13 @@ + + +Budibase Logo $goto("./apps")} /> + + diff --git a/packages/builder/src/stores/portal/admin.js b/packages/builder/src/stores/portal/admin.js index 2106acac27..29d4585c06 100644 --- a/packages/builder/src/stores/portal/admin.js +++ b/packages/builder/src/stores/portal/admin.js @@ -17,6 +17,7 @@ export const DEFAULT_CONFIG = { adminUser: { checked: false }, sso: { checked: false }, }, + maintenance: [], offlineMode: false, } @@ -48,6 +49,7 @@ export function createAdminStore() { store.isDev = environment.isDev store.baseUrl = environment.baseUrl store.offlineMode = environment.offlineMode + store.maintenance = environment.maintenance return store }) } diff --git a/packages/types/src/core/installation.ts b/packages/types/src/core/installation.ts index 7679290f36..ec89e439d9 100644 --- a/packages/types/src/core/installation.ts +++ b/packages/types/src/core/installation.ts @@ -2,3 +2,7 @@ export enum ServiceType { WORKER = "worker", APPS = "apps", } + +export enum MaintenanceType { + SQS_MISSING = "sqs_missing", +} diff --git a/packages/worker/src/api/controllers/system/environment.ts b/packages/worker/src/api/controllers/system/environment.ts index bf9270607f..6171ccf4db 100644 --- a/packages/worker/src/api/controllers/system/environment.ts +++ b/packages/worker/src/api/controllers/system/environment.ts @@ -1,10 +1,18 @@ -import { Ctx } from "@budibase/types" +import { Ctx, MaintenanceType } from "@budibase/types" import env from "../../../environment" import { env as coreEnv } from "@budibase/backend-core" import nodeFetch from "node-fetch" +// When we come to move to SQS fully and move away from Clouseau, we will need +// to flip this to true (or remove it entirely). This will then be used to +// determine if we should show the maintenance page that links to the SQS +// migration docs. +const sqsRequired = false + let sqsAvailable: boolean async function isSqsAvailable() { + // We cache this value for the duration of the Node process because we don't + // want every page load to be making this relatively expensive check. if (sqsAvailable !== undefined) { return sqsAvailable } @@ -21,6 +29,10 @@ async function isSqsAvailable() { } } +async function isSqsMissing() { + return sqsRequired && !(await isSqsAvailable()) +} + export const fetch = async (ctx: Ctx) => { ctx.body = { multiTenancy: !!env.MULTI_TENANCY, @@ -33,8 +45,9 @@ export const fetch = async (ctx: Ctx) => { } if (env.SELF_HOSTED) { - ctx.body.infrastructure = { - sqs: await isSqsAvailable(), + ctx.body.maintenance = [] + if (await isSqsMissing()) { + ctx.body.maintenance.push({ type: MaintenanceType.SQS_MISSING }) } } } diff --git a/packages/worker/src/api/routes/system/tests/environment.spec.ts b/packages/worker/src/api/routes/system/tests/environment.spec.ts index 2efbfa07c9..4dee77d3a9 100644 --- a/packages/worker/src/api/routes/system/tests/environment.spec.ts +++ b/packages/worker/src/api/routes/system/tests/environment.spec.ts @@ -40,9 +40,7 @@ describe("/api/system/environment", () => { multiTenancy: true, baseUrl: "http://localhost:10000", offlineMode: false, - infrastructure: { - sqs: false, - }, + maintenance: [], }) }) }) From 281b88a86adac77f06e6295cb584095aec87d046 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 31 Jan 2024 15:54:36 +0000 Subject: [PATCH 02/10] Respond to PR feedback. --- packages/worker/src/api/controllers/system/environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/worker/src/api/controllers/system/environment.ts b/packages/worker/src/api/controllers/system/environment.ts index 6171ccf4db..203d3d41ff 100644 --- a/packages/worker/src/api/controllers/system/environment.ts +++ b/packages/worker/src/api/controllers/system/environment.ts @@ -42,10 +42,10 @@ export const fetch = async (ctx: Ctx) => { disableAccountPortal: env.DISABLE_ACCOUNT_PORTAL, baseUrl: env.PLATFORM_URL, isDev: env.isDev() && !env.isTest(), + maintenance: [], } if (env.SELF_HOSTED) { - ctx.body.maintenance = [] if (await isSqsMissing()) { ctx.body.maintenance.push({ type: MaintenanceType.SQS_MISSING }) } From b52ba43979b2d7a397356300c5e291edf0d3b35a Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 31 Jan 2024 15:56:17 +0000 Subject: [PATCH 03/10] Fix tests. --- packages/worker/src/api/routes/system/tests/environment.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/worker/src/api/routes/system/tests/environment.spec.ts b/packages/worker/src/api/routes/system/tests/environment.spec.ts index 4dee77d3a9..dbe9be7374 100644 --- a/packages/worker/src/api/routes/system/tests/environment.spec.ts +++ b/packages/worker/src/api/routes/system/tests/environment.spec.ts @@ -27,6 +27,7 @@ describe("/api/system/environment", () => { multiTenancy: true, baseUrl: "http://localhost:10000", offlineMode: false, + maintenance: [], }) }) From 5dbe68a9b1d9342afce35a9b6142c40cd7661861 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 21 Feb 2024 11:03:58 +0000 Subject: [PATCH 04/10] Restyle maintenance page. --- .../pages/builder/maintenance/index.svelte | 123 +++++++++++++++--- 1 file changed, 102 insertions(+), 21 deletions(-) diff --git a/packages/builder/src/pages/builder/maintenance/index.svelte b/packages/builder/src/pages/builder/maintenance/index.svelte index bdadd98c42..0658ac3e3a 100644 --- a/packages/builder/src/pages/builder/maintenance/index.svelte +++ b/packages/builder/src/pages/builder/maintenance/index.svelte @@ -1,27 +1,108 @@ -{#each $admin.maintenance as maintenance} - {#if maintenance.type === MaintenanceType.SQS_MISSING} - - - - Please upgrade your Budibase installation - - We've detected that the version of Budibase you're using depends on a - more recent version of the CouchDB database than what you have - installed. - - - To resolve this, you can either rollback to a previous version of - Budibase, or follow the migration guide here - to update to a later version of CouchDB. - - - - {/if} -{/each} +
+
+
+ +
+
+ {#each $admin.maintenance as maintenance} + {#if maintenance.type === MaintenanceType.SQS_MISSING} +

Please upgrade your Budibase installation

+

+ We've detected that the version of Budibase you're using depends on + a more recent version of the CouchDB database than what you have + installed. +

+

+ To resolve this, you can either rollback to a previous version of + Budibase, or follow the migration guide to update to a later version + of CouchDB. +

+ + {/if} + {/each} +
+
+
+ + From 19803f91826feb1163ac3dbd416e38e9efb9c8ee Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 11 Mar 2024 15:19:23 +0000 Subject: [PATCH 05/10] Use BBUI components instead of raw HTML. --- .../pages/builder/maintenance/index.svelte | 86 ++++++------------- .../src/api/controllers/system/environment.ts | 3 + 2 files changed, 30 insertions(+), 59 deletions(-) diff --git a/packages/builder/src/pages/builder/maintenance/index.svelte b/packages/builder/src/pages/builder/maintenance/index.svelte index 0658ac3e3a..95080d0563 100644 --- a/packages/builder/src/pages/builder/maintenance/index.svelte +++ b/packages/builder/src/pages/builder/maintenance/index.svelte @@ -1,5 +1,6 @@ @@ -9,25 +10,26 @@
-
+
{#each $admin.maintenance as maintenance} {#if maintenance.type === MaintenanceType.SQS_MISSING} -

Please upgrade your Budibase installation

-

- We've detected that the version of Budibase you're using depends on - a more recent version of the CouchDB database than what you have - installed. -

-

- To resolve this, you can either rollback to a previous version of - Budibase, or follow the migration guide to update to a later version - of CouchDB. -

- + + Please upgrade your Budibase installation + + We've detected that the version of Budibase you're using depends + on a more recent version of the CouchDB database than what you + have installed. + + + To resolve this, you can either rollback to a previous version of + Budibase, or follow the migration guide to update to a later + version of CouchDB. + + + {/if} {/each}
@@ -35,27 +37,7 @@
diff --git a/packages/client/src/index.js b/packages/client/src/index.js index 2c8d310619..9a2f0addbc 100644 --- a/packages/client/src/index.js +++ b/packages/client/src/index.js @@ -1,5 +1,6 @@ import ClientApp from "./components/ClientApp.svelte" import UpdatingApp from "./components/UpdatingApp.svelte" +import MaintenanceScreen from "./components/MaintenanceScreen.svelte" import { builderStore, appStore, @@ -65,6 +66,15 @@ const loadBudibase = async () => { await environmentStore.actions.fetchEnvironment() } + const maintenanceList = get(environmentStore)?.maintenance + if (maintenanceList?.length > 0) { + new MaintenanceScreen({ + target: window.document.body, + props: { maintenanceList }, + }) + return + } + // Register handler for runtime events from the builder window.handleBuilderRuntimeEvent = (type, data) => { if (!window["##BUDIBASE_IN_BUILDER##"]) { From fcd7ee10f1bcc7ba76fb0f78e8f23362abd73323 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 14 Mar 2024 09:57:00 +0000 Subject: [PATCH 07/10] Create app user facing maintenance page. --- .../pages/builder/maintenance/index.svelte | 6 + .../client/src/components/ClientApp.svelte | 210 +++++++++--------- .../src/components/MaintenanceScreen.svelte | 31 +-- packages/client/src/index.js | 10 - 4 files changed, 132 insertions(+), 125 deletions(-) diff --git a/packages/builder/src/pages/builder/maintenance/index.svelte b/packages/builder/src/pages/builder/maintenance/index.svelte index 95080d0563..1735a93e84 100644 --- a/packages/builder/src/pages/builder/maintenance/index.svelte +++ b/packages/builder/src/pages/builder/maintenance/index.svelte @@ -3,6 +3,12 @@ import { Heading, Body, Button, Layout } from "@budibase/bbui" import { admin } from "stores/portal" import BudibaseLogo from "../portal/_components/BudibaseLogo.svelte" + + $: { + if ($admin.maintenance.length === 0) { + window.location = "/builder" + } + }
diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index 4efa8af4e6..7e30e21ae8 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -17,6 +17,7 @@ appStore, devToolsStore, devToolsEnabled, + environmentStore, } from "stores" import NotificationDisplay from "components/overlay/NotificationDisplay.svelte" import ConfirmationDisplay from "components/overlay/ConfirmationDisplay.svelte" @@ -36,6 +37,7 @@ import DevToolsHeader from "components/devtools/DevToolsHeader.svelte" import DevTools from "components/devtools/DevTools.svelte" import FreeFooter from "components/FreeFooter.svelte" + import MaintenanceScreen from "components/MaintenanceScreen.svelte" import licensing from "../licensing" // Provide contexts @@ -111,122 +113,128 @@ class="spectrum spectrum--medium {$themeStore.baseTheme} {$themeStore.theme}" class:builder={$builderStore.inBuilder} > - - - - - - - - {#key $builderStore.selectedComponentId} - {#if $builderStore.inBuilder} - - {/if} - {/key} - - -
- -
- {#if showDevTools} - + {#if $environmentStore.maintenance.length > 0} + + {:else} + + + + + + + + {#key $builderStore.selectedComponentId} + {#if $builderStore.inBuilder} + {/if} + {/key} -
- {#if permissionError} -
- - - {@html ErrorSVG} - - You don't have permission to use this app - - - Ask your administrator to grant you access - - -
- {:else if !$screenStore.activeLayout} -
- - - {@html ErrorSVG} - - Something went wrong rendering your app - - - Get in touch with support if this issue persists - - -
- {:else if embedNoScreens} -
- - - {@html ErrorSVG} - - This Budibase app is not publicly accessible - - -
- {:else} - - {#key $screenStore.activeLayout._id} - - {/key} + +
+ +
+ {#if showDevTools} + + {/if} - + {@html ErrorSVG} + + You don't have permission to use this app + + + Ask your administrator to grant you access + + +
+ {:else if !$screenStore.activeLayout} +
+ + + {@html ErrorSVG} + + Something went wrong rendering your app + + + Get in touch with support if this issue persists + + +
+ {:else if embedNoScreens} +
+ + + {@html ErrorSVG} + + This Budibase app is not publicly accessible + + +
+ {:else} + + {#key $screenStore.activeLayout._id} + + {/key} + + -
+
- - - {#if !$builderStore.inBuilder && licensing.logoEnabled()} - + + {#if $appStore.isDevApp} + + {/if} + {#if $builderStore.inBuilder || $devToolsStore.allowSelection} + + {/if} + {#if $builderStore.inBuilder} + + {/if}
- - - {#if $appStore.isDevApp} - - {/if} - {#if $builderStore.inBuilder || $devToolsStore.allowSelection} - - {/if} - {#if $builderStore.inBuilder} - - - {/if} -
- - - - - + + + + + + {/if}
{/if} diff --git a/packages/client/src/components/MaintenanceScreen.svelte b/packages/client/src/components/MaintenanceScreen.svelte index b43525fdb6..529f20781a 100644 --- a/packages/client/src/components/MaintenanceScreen.svelte +++ b/packages/client/src/components/MaintenanceScreen.svelte @@ -1,6 +1,17 @@ + @@ -11,22 +22,14 @@ {#each maintenanceList as maintenance} {#if maintenance.type === MaintenanceType.SQS_MISSING} - Please upgrade your Budibase installation + Budibase installation requires maintenance - We've detected that the version of Budibase you're using depends - on a more recent version of the CouchDB database than what you - have installed. - - - To resolve this, you can either rollback to a previous version of - Budibase, or follow the migration guide to update to a later - version of CouchDB. + The administrator of this Budibase installation needs to take + actions to update components that are out of date. Please contact + them and show them this warning. More information will be + available when they log into their account. - {/if} {/each}
diff --git a/packages/client/src/index.js b/packages/client/src/index.js index 9a2f0addbc..2c8d310619 100644 --- a/packages/client/src/index.js +++ b/packages/client/src/index.js @@ -1,6 +1,5 @@ import ClientApp from "./components/ClientApp.svelte" import UpdatingApp from "./components/UpdatingApp.svelte" -import MaintenanceScreen from "./components/MaintenanceScreen.svelte" import { builderStore, appStore, @@ -66,15 +65,6 @@ const loadBudibase = async () => { await environmentStore.actions.fetchEnvironment() } - const maintenanceList = get(environmentStore)?.maintenance - if (maintenanceList?.length > 0) { - new MaintenanceScreen({ - target: window.document.body, - props: { maintenanceList }, - }) - return - } - // Register handler for runtime events from the builder window.handleBuilderRuntimeEvent = (type, data) => { if (!window["##BUDIBASE_IN_BUILDER##"]) { From c8f37e16e567af9c8f9376f17eff99da44814018 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 14 Mar 2024 10:23:42 +0000 Subject: [PATCH 08/10] CSS tweaks. --- .../pages/builder/maintenance/index.svelte | 1 + .../src/components/MaintenanceScreen.svelte | 56 ++++++------------- 2 files changed, 19 insertions(+), 38 deletions(-) diff --git a/packages/builder/src/pages/builder/maintenance/index.svelte b/packages/builder/src/pages/builder/maintenance/index.svelte index 1735a93e84..e4c379885a 100644 --- a/packages/builder/src/pages/builder/maintenance/index.svelte +++ b/packages/builder/src/pages/builder/maintenance/index.svelte @@ -51,6 +51,7 @@ flex-direction: row; align-items: center; justify-content: center; + padding: var(--spacing-l); } .hero { margin: var(--spacing-l); diff --git a/packages/client/src/components/MaintenanceScreen.svelte b/packages/client/src/components/MaintenanceScreen.svelte index 529f20781a..a44c1292dd 100644 --- a/packages/client/src/components/MaintenanceScreen.svelte +++ b/packages/client/src/components/MaintenanceScreen.svelte @@ -16,28 +16,24 @@ export let maintenanceList -
-
-
- {#each maintenanceList as maintenance} - {#if maintenance.type === MaintenanceType.SQS_MISSING} - - Budibase installation requires maintenance - - The administrator of this Budibase installation needs to take - actions to update components that are out of date. Please contact - them and show them this warning. More information will be - available when they log into their account. - - - {/if} - {/each} -
-
+
+ {#each maintenanceList as maintenance} + {#if maintenance.type === MaintenanceType.SQS_MISSING} + + Budibase installation requires maintenance + + The administrator of this Budibase installation needs to take actions + to update components that are out of date. Please contact them and + show them this warning. More information will be available when they + log into their account. + + + {/if} + {/each}
From 5918dfebbaecd6a7d79f82bd93d7dbb5f4a1c2bd Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 14 Mar 2024 10:25:41 +0000 Subject: [PATCH 09/10] Silence lint warnings. --- .../src/pages/builder/portal/_components/BudibaseLogo.svelte | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/builder/src/pages/builder/portal/_components/BudibaseLogo.svelte b/packages/builder/src/pages/builder/portal/_components/BudibaseLogo.svelte index 8276510201..b0dc4cda50 100644 --- a/packages/builder/src/pages/builder/portal/_components/BudibaseLogo.svelte +++ b/packages/builder/src/pages/builder/portal/_components/BudibaseLogo.svelte @@ -3,6 +3,8 @@ import { goto } from "@roxi/routify" + + Budibase Logo $goto("./apps")} />