From 54502280de6d3e2856e943808d09a2406b45c44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Guti=C3=A9rrez=20Hermoso?= Date: Wed, 14 Aug 2024 16:14:13 -0400 Subject: [PATCH] (core) AdminPanel: hide the enterprise toggle in core and grist-ee images Summary: In the pure OSS `grist-oss` image, the `ActivationPage` module from stubs is used, as the `ext` code is completely missing. We can easily just always return `false` here. In the case when the `ext` directory exists, this may mean we're in the standard `grist` image or the `grist-ee` image. The latter is distinguished by having `GRIST_FORCE_ENABLE_ENTERPRISE` so we check if that's on, and hide the toggle accordingly if so. Test Plan: Use these changes to build the three Docker images (`grist-oss`, `grist`, and `grist-ee`) and verify that only `grist` shows the toggle. Reviewers: jarek Reviewed By: jarek Subscribers: jarek Differential Revision: https://phab.getgrist.com/D4321 --- app/client/ui/AdminPanel.ts | 22 +++++++++++++++------- app/common/gristUrls.ts | 3 +++ app/server/lib/sendAppPage.ts | 1 + stubs/app/client/ui/ActivationPage.ts | 5 +++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/client/ui/AdminPanel.ts b/app/client/ui/AdminPanel.ts index ae1fa8ef..e2cc38bf 100644 --- a/app/client/ui/AdminPanel.ts +++ b/app/client/ui/AdminPanel.ts @@ -26,6 +26,7 @@ import {Computed, Disposable, dom, IDisposable, IDisposableOwner, MultiHolder, Observable, styled} from 'grainjs'; import {AdminSection, AdminSectionItem, HidableToggle} from 'app/client/ui/AdminPanelCss'; import {getAdminPanelName} from 'app/client/ui/AdminPanelName'; +import {showEnterpriseToggle} from 'app/client/ui/ActivationPage'; const t = makeT('AdminPanel'); @@ -158,13 +159,7 @@ Please log in as an administrator.`)), description: t('Current version of Grist'), value: cssValueLabel(`Version ${version.version}`), }), - dom.create(AdminSectionItem, { - id: 'enterprise', - name: t('Enterprise'), - description: t('Enable Grist Enterprise'), - value: dom.create(HidableToggle, this._toggleEnterprise.getEnterpriseToggleObservable()), - expandedContent: this._toggleEnterprise.buildEnterpriseSection(), - }), + this._maybeAddEnterpriseToggle(), this._buildUpdates(owner), ]), dom.create(AdminSection, t('Self Checks'), [ @@ -186,6 +181,19 @@ Please log in as an administrator.`)), ]; } + private _maybeAddEnterpriseToggle() { + if (!showEnterpriseToggle()) { + return null; + } + return dom.create(AdminSectionItem, { + id: 'enterprise', + name: t('Enterprise'), + description: t('Enable Grist Enterprise'), + value: dom.create(HidableToggle, this._toggleEnterprise.getEnterpriseToggleObservable()), + expandedContent: this._toggleEnterprise.buildEnterpriseSection(), + }); + } + private _buildSandboxingDisplay(owner: IDisposableOwner) { return dom.domComputed( use => { diff --git a/app/common/gristUrls.ts b/app/common/gristUrls.ts index e8410e1d..6cbe7d77 100644 --- a/app/common/gristUrls.ts +++ b/app/common/gristUrls.ts @@ -810,6 +810,9 @@ export interface GristLoadConfig { // The Grist deployment type (e.g. core, enterprise). deploymentType?: GristDeploymentType; + // Force enterprise deployment? For backwards compatibility with grist-ee Docker image + forceEnableEnterprise?: boolean; + // The org containing public templates and tutorials. templateOrg?: string|null; diff --git a/app/server/lib/sendAppPage.ts b/app/server/lib/sendAppPage.ts index 653028a7..38f3dcb5 100644 --- a/app/server/lib/sendAppPage.ts +++ b/app/server/lib/sendAppPage.ts @@ -96,6 +96,7 @@ export function makeGristConfig(options: MakeGristConfigOptions): GristLoadConfi userLocale: (req as RequestWithLogin | undefined)?.user?.options?.locale, telemetry: server?.getTelemetry().getTelemetryConfig(req as RequestWithLogin | undefined), deploymentType: server?.getDeploymentType(), + forceEnableEnterprise: isAffirmative(process.env.GRIST_FORCE_ENABLE_ENTERPRISE), templateOrg: getTemplateOrg(), onboardingTutorialDocId: getOnboardingTutorialDocId(), canCloseAccount: isAffirmative(process.env.GRIST_ACCOUNT_CLOSE), diff --git a/stubs/app/client/ui/ActivationPage.ts b/stubs/app/client/ui/ActivationPage.ts index 99b90e57..cc65c547 100644 --- a/stubs/app/client/ui/ActivationPage.ts +++ b/stubs/app/client/ui/ActivationPage.ts @@ -5,3 +5,8 @@ import { export function getActivationPage(): IActivationPageCreator { return DefaultActivationPage; } + +export function showEnterpriseToggle() { + // To be changed by enterprise module + return false; +}