Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Maps] Always check license at plugin startup (#87873) #88735

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions x-pack/plugins/maps/public/licensed_features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,40 @@ export const LICENCED_FEATURES_DETAILS: Record<LICENSED_FEATURES, LicensedFeatur

let licenseId: string | undefined;
let isGoldPlus: boolean = false;

let isEnterprisePlus: boolean = false;

export const getLicenseId = () => 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 whenLicenseInitialized = async (): Promise<void> => {
await licenseInitialized;
};

export async function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) {
const license = await licensingPlugin.refresh();
updateLicenseState(license);

licensingPluginStart = licensingPlugin;
licensingPluginStart.license$.subscribe(updateLicenseState);

initializeLicense(undefined);
}

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 function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup) {
for (const licensedFeature of Object.values(LICENSED_FEATURES)) {
licensingPlugin.featureUsage.register(
Expand All @@ -53,20 +79,6 @@ 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';

licenseId = license.uid;
});
}

export function notifyLicensedFeatureUsage(licensedFeature: LICENSED_FEATURES) {
if (!licensingPluginStart) {
// eslint-disable-next-line no-console
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,6 +88,8 @@ export class SavedMap {
}

async whenReady() {
await whenLicenseInitialized();

if (!this._mapEmbeddableInput) {
this._attributes = {
title: '',
Expand Down