From fb23b203cbe9b9555685f0798ca6916b9ab3252b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 11 Jan 2021 12:07:58 -0500 Subject: [PATCH 1/5] init --- .../plugins/maps/public/licensed_features.ts | 24 ++++++++++++------- x-pack/plugins/maps/public/plugin.ts | 4 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/maps/public/licensed_features.ts b/x-pack/plugins/maps/public/licensed_features.ts index f709dd529e375..f16fcac900683 100644 --- a/x-pack/plugins/maps/public/licensed_features.ts +++ b/x-pack/plugins/maps/public/licensed_features.ts @@ -54,17 +54,23 @@ export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup) } let licensingPluginStart: LicensingPluginStart; -export function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) { - licensingPluginStart = licensingPlugin; - licensingPluginStart.license$.subscribe((license: ILicense) => { - const gold = license.check(APP_ID, 'gold'); - isGoldPlus = gold.state === 'valid'; - const enterprise = license.check(APP_ID, 'enterprise'); - isEnterprisePlus = enterprise.state === 'valid'; +function updateLicenseState(license: ILicense) { + const gold = license.check(APP_ID, 'gold'); + isGoldPlus = gold.state === 'valid'; + + const enterprise = license.check(APP_ID, 'enterprise'); + isEnterprisePlus = enterprise.state === 'valid'; + + licenseId = license.uid; +} + +export async function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) { + const license = await licensingPlugin.refresh(); + updateLicenseState(license); - licenseId = license.uid; - }); + licensingPluginStart = licensingPlugin; + licensingPluginStart.license$.subscribe(updateLicenseState); } export function notifyLicensedFeatureUsage(licensedFeature: LICENSED_FEATURES) { diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 8bffea3ce5a87..b5340f4e31068 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -158,8 +158,8 @@ export class MapsPlugin }); } - public start(core: CoreStart, plugins: MapsPluginStartDependencies): MapsStartApi { - setLicensingPluginStart(plugins.licensing); + public async start(core: CoreStart, plugins: MapsPluginStartDependencies): Promise { + await setLicensingPluginStart(plugins.licensing); plugins.uiActions.addTriggerAction(VISUALIZE_GEO_FIELD_TRIGGER, visualizeGeoFieldAction); setStartServices(core, plugins); // unregisters the OSS alias From 455d7acf32a82f7ed2802b721db900f2c9f937d1 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 12 Jan 2021 15:32:25 -0500 Subject: [PATCH 2/5] remove blocking behavior --- x-pack/plugins/maps/public/licensed_features.ts | 1 - x-pack/plugins/maps/public/plugin.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/maps/public/licensed_features.ts b/x-pack/plugins/maps/public/licensed_features.ts index f16fcac900683..e39f8d672ae21 100644 --- a/x-pack/plugins/maps/public/licensed_features.ts +++ b/x-pack/plugins/maps/public/licensed_features.ts @@ -36,7 +36,6 @@ export const LICENCED_FEATURES_DETAILS: Record licenseId; diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index b5340f4e31068..8d9ea83e1cfd2 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -158,8 +158,8 @@ export class MapsPlugin }); } - public async start(core: CoreStart, plugins: MapsPluginStartDependencies): Promise { - await setLicensingPluginStart(plugins.licensing); + public start(core: CoreStart, plugins: MapsPluginStartDependencies): Promise { + setLicensingPluginStart(plugins.licensing); plugins.uiActions.addTriggerAction(VISUALIZE_GEO_FIELD_TRIGGER, visualizeGeoFieldAction); setStartServices(core, plugins); // unregisters the OSS alias From 37cfeb6d5aa37f0b4b0e43a2da83bbbbbe6abbf7 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 13 Jan 2021 14:40:21 -0500 Subject: [PATCH 3/5] delay map availability until license-state is initialized --- x-pack/plugins/maps/public/licensed_features.ts | 10 ++++++++++ .../maps/public/routes/map_page/saved_map/saved_map.ts | 3 +++ 2 files changed, 13 insertions(+) diff --git a/x-pack/plugins/maps/public/licensed_features.ts b/x-pack/plugins/maps/public/licensed_features.ts index e39f8d672ae21..049087d5fbf1d 100644 --- a/x-pack/plugins/maps/public/licensed_features.ts +++ b/x-pack/plugins/maps/public/licensed_features.ts @@ -41,7 +41,15 @@ let isEnterprisePlus: boolean = false; export const getLicenseId = () => licenseId; export const getIsGoldPlus = () => isGoldPlus; +let initializeLicense: (value: unknown) => void; +const licenseInitialized = new Promise((resolve) => { + initializeLicense = resolve; +}); + export const getIsEnterprisePlus = () => isEnterprisePlus; +export const whenLicenseInitialized = async (): Promise => { + await licenseInitialized; +}; export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup) { for (const licensedFeature of Object.values(LICENSED_FEATURES)) { @@ -70,6 +78,8 @@ export async function setLicensingPluginStart(licensingPlugin: LicensingPluginSt licensingPluginStart = licensingPlugin; licensingPluginStart.license$.subscribe(updateLicenseState); + + initializeLicense(undefined); } export function notifyLicensedFeatureUsage(licensedFeature: LICENSED_FEATURES) { diff --git a/x-pack/plugins/maps/public/routes/map_page/saved_map/saved_map.ts b/x-pack/plugins/maps/public/routes/map_page/saved_map/saved_map.ts index 3530e3cc615ad..ae54228854483 100644 --- a/x-pack/plugins/maps/public/routes/map_page/saved_map/saved_map.ts +++ b/x-pack/plugins/maps/public/routes/map_page/saved_map/saved_map.ts @@ -45,6 +45,7 @@ import { copyPersistentState } from '../../../reducers/util'; import { getBreadcrumbs } from './get_breadcrumbs'; import { DEFAULT_IS_LAYER_TOC_OPEN } from '../../../reducers/ui'; import { createBasemapLayerDescriptor } from '../../../classes/layers/create_basemap_layer_descriptor'; +import { whenLicenseInitialized } from '../../../licensed_features'; export class SavedMap { private _attributes: MapSavedObjectAttributes | null = null; @@ -87,6 +88,8 @@ export class SavedMap { } async whenReady() { + await whenLicenseInitialized(); + if (!this._mapEmbeddableInput) { this._attributes = { title: '', From efc4a6720483558561e92add13039d9dabd47c15 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 14 Jan 2021 16:13:09 -0500 Subject: [PATCH 4/5] revert change --- x-pack/plugins/maps/public/plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 8d9ea83e1cfd2..8bffea3ce5a87 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -158,7 +158,7 @@ export class MapsPlugin }); } - public start(core: CoreStart, plugins: MapsPluginStartDependencies): Promise { + public start(core: CoreStart, plugins: MapsPluginStartDependencies): MapsStartApi { setLicensingPluginStart(plugins.licensing); plugins.uiActions.addTriggerAction(VISUALIZE_GEO_FIELD_TRIGGER, visualizeGeoFieldAction); setStartServices(core, plugins); From 89a72405f3bec2c5718719f473d20ecdc70b5cec Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 15 Jan 2021 16:38:06 -0500 Subject: [PATCH 5/5] organize for clarity --- .../plugins/maps/public/licensed_features.ts | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/maps/public/licensed_features.ts b/x-pack/plugins/maps/public/licensed_features.ts index 049087d5fbf1d..43a574b5a17c8 100644 --- a/x-pack/plugins/maps/public/licensed_features.ts +++ b/x-pack/plugins/maps/public/licensed_features.ts @@ -37,30 +37,28 @@ export const LICENCED_FEATURES_DETAILS: Record licenseId; export const getIsGoldPlus = () => isGoldPlus; +export const getIsEnterprisePlus = () => isEnterprisePlus; +let licensingPluginStart: LicensingPluginStart; let initializeLicense: (value: unknown) => void; const licenseInitialized = new Promise((resolve) => { initializeLicense = resolve; }); - -export const getIsEnterprisePlus = () => isEnterprisePlus; export const whenLicenseInitialized = async (): Promise => { await licenseInitialized; }; -export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup) { - for (const licensedFeature of Object.values(LICENSED_FEATURES)) { - licensingPlugin.featureUsage.register( - LICENCED_FEATURES_DETAILS[licensedFeature].name, - LICENCED_FEATURES_DETAILS[licensedFeature].license - ); - } -} +export async function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) { + const license = await licensingPlugin.refresh(); + updateLicenseState(license); -let licensingPluginStart: LicensingPluginStart; + licensingPluginStart = licensingPlugin; + licensingPluginStart.license$.subscribe(updateLicenseState); + + initializeLicense(undefined); +} function updateLicenseState(license: ILicense) { const gold = license.check(APP_ID, 'gold'); @@ -72,14 +70,13 @@ function updateLicenseState(license: ILicense) { licenseId = license.uid; } -export async function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) { - const license = await licensingPlugin.refresh(); - updateLicenseState(license); - - licensingPluginStart = licensingPlugin; - licensingPluginStart.license$.subscribe(updateLicenseState); - - initializeLicense(undefined); +export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup) { + for (const licensedFeature of Object.values(LICENSED_FEATURES)) { + licensingPlugin.featureUsage.register( + LICENCED_FEATURES_DETAILS[licensedFeature].name, + LICENCED_FEATURES_DETAILS[licensedFeature].license + ); + } } export function notifyLicensedFeatureUsage(licensedFeature: LICENSED_FEATURES) {