Skip to content

Commit

Permalink
updated at 2024-06-17T14:31:43-04:00
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfitz committed Jun 17, 2024
1 parent 6c0d667 commit 2f6999e
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 45 deletions.
25 changes: 19 additions & 6 deletions ext/app/client/components/Banners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,29 @@
*/

import {buildActivationBanner} from 'app/client/components/ActivationBanner';
import * as CoreBanners from 'app/client/components/CoreBanners';
import {DocUsageBanner} from 'app/client/components/DocUsageBanner';
import {SiteUsageBanner} from 'app/client/components/SiteUsageBanner';
import {AppModel} from 'app/client/models/AppModel';
import {DocPageModel} from 'app/client/models/DocPageModel';
import {dom} from 'grainjs';
import {createEnterpriseSpecificFunc} from "app/client/lib/enterpriseDeploymentCheck";

export function buildHomeBanners(app: AppModel) {
return buildActivationBanner() || dom.create(SiteUsageBanner, app);
}
const EEBanners = {
buildHomeBanners(app: AppModel) {
return buildActivationBanner() || dom.create(SiteUsageBanner, app);
},
buildDocumentBanners(docPageModel: DocPageModel) {
return buildActivationBanner() || dom.create(DocUsageBanner, docPageModel);
}
};

export function buildDocumentBanners(docPageModel: DocPageModel) {
return buildActivationBanner() || dom.create(DocUsageBanner, docPageModel);
}
export const buildHomeBanners = createEnterpriseSpecificFunc(
EEBanners.buildHomeBanners,
CoreBanners.buildHomeBanners
);

export const buildDocumentBanners = createEnterpriseSpecificFunc(
EEBanners.buildDocumentBanners,
CoreBanners.buildDocumentBanners
);
22 changes: 22 additions & 0 deletions ext/app/client/lib/enterpriseDeploymentCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { GristDeploymentType } from "app/common/gristUrls";
import { getGristConfig } from "app/common/urlUtils";

const enterpriseDeploymentTypes: GristDeploymentType[] = ['saas', 'enterprise'];
export function isEnterpriseDeployment(): boolean {
return enterpriseDeploymentTypes.includes(getGristConfig().deploymentType ?? 'core');
}

/**
* Calls one of the provided callbacks at call time, based on the edition of grist that's running.
* @param enterpriseCallback - Called when an enterprise deployment type is used.
* @param nonEnterpriseCallback - Called for non-enterprise deployment types (e.g. core, desktop).
*/
export function createEnterpriseSpecificFunc<P extends any[], R>(
enterpriseCallback: (...args: P) => R,
nonEnterpriseCallback: (...args: P) => R
)
{
return function callCorrectCallback(...args: P): R {
return isEnterpriseDeployment() ? enterpriseCallback(...args) : nonEnterpriseCallback(...args);
};
}
10 changes: 8 additions & 2 deletions ext/app/client/ui/ActivationPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {ActivationModel, ActivationModelImpl} from 'app/client/models/Activation
import {urlState} from 'app/client/models/gristUrlState';
import * as css from 'app/client/ui/ActivationPageCss';
import {AppHeader} from 'app/client/ui/AppHeader';
import {DefaultActivationPage, IActivationPageCreator} from 'app/client/ui/DefaultActivationPage';
import {createForbiddenPage} from 'app/client/ui/errorPages';
import {leftPanelBasic} from 'app/client/ui/LeftPanelCommon';
import {pagePanels} from 'app/client/ui/PagePanels';
Expand All @@ -13,13 +14,18 @@ import {bigPrimaryButtonLink} from 'app/client/ui2018/buttons';
import {cssLink} from 'app/client/ui2018/links';
import {loadingSpinner} from 'app/client/ui2018/loaders';
import {IActivationStatus} from 'app/common/ActivationAPI';
import {commonUrls, getPageTitleSuffix} from 'app/common/gristUrls';
import { commonUrls, getPageTitleSuffix } from 'app/common/gristUrls';
import {getGristConfig} from 'app/common/urlUtils';
import {Computed, Disposable, dom, makeTestId, Observable, subscribe} from 'grainjs';
import {isEnterpriseDeployment} from "app/client/lib/enterpriseDeploymentCheck";

const testId = makeTestId('test-ap-');

export class ActivationPage extends Disposable {
export function getActivationPage(): IActivationPageCreator {
return isEnterpriseDeployment() ? EnterpriseActivationPage : DefaultActivationPage;
}

export class EnterpriseActivationPage extends Disposable {
private readonly _currentPage = Computed.create(this, urlState().state, (_use, s) => s.activation);
private _model: ActivationModel = new ActivationModelImpl(this._appModel);

Expand Down
34 changes: 11 additions & 23 deletions ext/app/client/ui/ProductUpgrades.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
import type {AppModel} from 'app/client/models/AppModel';
import {PlanSelection} from 'app/common/BillingAPI';
import {commonUrls} from 'app/common/gristUrls';
import {Disposable, DomArg, DomContents, IDisposableOwner} from 'grainjs';
import { commonUrls } from 'app/common/gristUrls';
import {Disposable} from 'grainjs';
import * as CoreTeamModals from "app/client/ui/CreateTeamModal";
import {createEnterpriseSpecificFunc} from "app/client/lib/enterpriseDeploymentCheck";

export async function buildNewSiteModal(context: Disposable, options: {
appModel: AppModel,
plan?: PlanSelection,
onCreate?: () => void
}) {
window.location.href = commonUrls.plans;
}
export const buildNewSiteModal = CoreTeamModals.buildNewSiteModal;

export async function buildUpgradeModal(owner: Disposable, options: {
async function buildEnterpriseUpgradeModal(owner: Disposable, options: {
appModel: AppModel,
pickPlan?: PlanSelection,
reason?: 'upgrade' | 'renew',
}) {
window.location.href = commonUrls.plans;
}

export function showTeamUpgradeConfirmation(owner: Disposable) {
}
export const buildUpgradeModal = createEnterpriseSpecificFunc(
buildEnterpriseUpgradeModal,
CoreTeamModals.buildUpgradeModal,
);

export interface UpgradeButton {
showUpgradeCard(...args: DomArg<HTMLElement>[]): DomContents;
showUpgradeButton(...args: DomArg<HTMLElement>[]): DomContents;
}

export function buildUpgradeButton(owner: IDisposableOwner, app: AppModel): UpgradeButton {
return {
showUpgradeCard : () => null,
showUpgradeButton : () => null,
};
}
export const buildUpgradeButton = CoreTeamModals.buildUpgradeButton;
23 changes: 18 additions & 5 deletions ext/app/server/lib/ActivationReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,25 @@ import * as fs from 'fs';
import * as jwt from 'jsonwebtoken';
import moment from 'moment';

const GRIST_ACTIVATION = process.env.GRIST_ACTIVATION;
const GRIST_ACTIVATION_FILE = process.env.GRIST_ACTIVATION_FILE;
const TEST_ENABLE_ACTIVATION = process.env.TEST_ENABLE_ACTIVATION;
/**
* Export dependencies to allow dynamic changes with unit tests.
* Proxy process.env to allow behaviour changes without explicitly depending on this file.
*/
export const Deps = {
get GRIST_ACTIVATION() {
return process.env.GRIST_ACTIVATION;
},
get GRIST_ACTIVATION_FILE() {
return process.env.GRIST_ACTIVATION_FILE;
},
get TEST_ENABLE_ACTIVATION() {
return process.env.TEST_ENABLE_ACTIVATION;
}
};

export const Deps = {GRIST_ACTIVATION, GRIST_ACTIVATION_FILE,
TEST_ENABLE_ACTIVATION};
// If any of the activation environment variables are set, assume the host is trying to run enterprise.
export const isRunningEnterprise =
() => Deps.GRIST_ACTIVATION || Deps.GRIST_ACTIVATION_FILE || Deps.TEST_ENABLE_ACTIVATION;

/**
* Plan: when grist-ee is installed, it will show a trial period
Expand Down
21 changes: 13 additions & 8 deletions ext/app/server/lib/create.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Activation } from 'app/gen-server/lib/Activation';
import { configureSendGridNotifier } from 'app/gen-server/lib/configureSendGridNotifier';
import { checkAzureExternalStorage,
configureAzureExternalStorage } from 'app/server/lib/configureAzureExternalStorage';
import { checkMinIOExternalStorage,
configureMinIOExternalStorage } from 'app/server/lib/configureMinIOExternalStorage';
import { checkS3ExternalStorage,
configureS3ExternalStorage } from 'app/server/lib/configureS3ExternalStorage';
import { makeSimpleCreator } from 'app/server/lib/ICreate';
import { checkAzureExternalStorage, configureAzureExternalStorage } from 'app/server/lib/configureAzureExternalStorage';
import { checkMinIOExternalStorage, configureMinIOExternalStorage } from 'app/server/lib/configureMinIOExternalStorage';
import { checkS3ExternalStorage, configureS3ExternalStorage } from 'app/server/lib/configureS3ExternalStorage';
import { ICreate, makeSimpleCreator } from 'app/server/lib/ICreate';
import { isRunningEnterprise } from 'app/server/lib/ActivationReader';
import { makeCoreCreator } from 'app/server/lib/coreCreator';

export const create = makeSimpleCreator({
export const makeEnterpriseCreator = () => makeSimpleCreator({
deploymentType: 'enterprise',
storage: [
{
Expand All @@ -34,3 +33,9 @@ export const create = makeSimpleCreator({
create: configureSendGridNotifier,
},
});

export const create = isRunningEnterprise() ? makeEnterpriseCreator() : makeCoreCreator();

export function getCreator(): ICreate {
return create;
}
7 changes: 6 additions & 1 deletion ext/app/server/lib/logins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import { GristLoginSystem } from 'app/server/lib/GristServer';
import { getMinimalLoginSystem } from 'app/server/lib/MinimalLogin';
import { getSamlLoginSystem } from 'app/server/lib/SamlConfig';
import { getConnectLoginSystem } from 'app/server/lib/GristConnect';
import { isRunningEnterprise } from "app/server/lib/ActivationReader";
import { getCoreLoginSystem } from 'app/server/lib/coreLogins';

export async function getLoginSystem(): Promise<GristLoginSystem> {
export async function getEnterpriseLoginSystem(): Promise<GristLoginSystem> {
return await getSamlLoginSystem() ||
await getForwardAuthLoginSystem() ||
await getConnectLoginSystem() ||
await getMinimalLoginSystem();
}

export const getLoginSystem: () => Promise<GristLoginSystem> =
isRunningEnterprise() ? getEnterpriseLoginSystem : getCoreLoginSystem;

0 comments on commit 2f6999e

Please sign in to comment.