[Maps] Add missing license to requests in maps embeddables (#59207) (#59334)

* Pull core service init out into separate function

* Call bind function from embeddable factory constructor

* Move inspector init back to start method. Remove old license check file

* Add TS types
This commit is contained in:
Aaron Caldwell 2020-03-04 12:03:14 -07:00 committed by GitHub
parent 20eeea2f29
commit 7f6ce76a84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 47 deletions

View file

@ -1,38 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
/**
* on the license information extracted from the xPackInfo.
* @param {XPackInfo} xPackInfo XPackInfo instance to extract license information from.
* @returns {LicenseCheckResult}
*/
export function checkLicense(xPackInfo) {
if (!xPackInfo.isAvailable()) {
return {
maps: false,
};
}
const isAnyXpackLicense = xPackInfo.license.isOneOf([
'basic',
'standard',
'gold',
'platinum',
'enterprise',
'trial',
]);
if (!isAnyXpackLicense) {
return {
maps: false,
};
}
return {
maps: true,
uid: xPackInfo.license.getUid(),
};
}

View file

@ -23,6 +23,8 @@ import { getQueryableUniqueIndexPatternIds } from '../selectors/map_selectors';
import { getInitialLayers } from '../angular/get_initial_layers';
import { mergeInputWithSavedMap } from './merge_input_with_saved_map';
import '../angular/services/gis_map_saved_object_loader';
import { bindSetupCoreAndPlugins } from '../plugin';
import { npSetup } from 'ui/new_platform';
export class MapEmbeddableFactory extends EmbeddableFactory {
type = MAP_SAVED_OBJECT_TYPE;
@ -37,6 +39,7 @@ export class MapEmbeddableFactory extends EmbeddableFactory {
getIconForSavedObject: () => APP_ICON,
},
});
bindSetupCoreAndPlugins(npSetup.core, npSetup.plugins);
}
isEditable() {
return capabilities.get().maps.save;

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { Plugin, CoreStart } from 'src/core/public';
import { Plugin, CoreStart, CoreSetup } from 'src/core/public';
// @ts-ignore
import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
@ -31,23 +31,25 @@ interface MapsPluginSetupDependencies {
};
}
export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => {
const { licensing } = plugins;
if (licensing) {
licensing.license$.subscribe(({ uid }: { uid: string }) => setLicenseId(uid));
}
};
/** @internal */
export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
public setup(
core: any,
{ __LEGACY: { uiModules }, np: { licensing, home } }: MapsPluginSetupDependencies
) {
public setup(core: CoreSetup, { __LEGACY: { uiModules }, np }: MapsPluginSetupDependencies) {
uiModules
.get('app/maps', ['ngRoute', 'react'])
.directive('mapListing', function(reactDirective: any) {
return reactDirective(wrapInI18nContext(MapListing));
});
if (licensing) {
licensing.license$.subscribe(({ uid }) => setLicenseId(uid));
}
bindSetupCoreAndPlugins(core, np);
home.featureCatalogue.register(featureCatalogueEntry);
np.home.featureCatalogue.register(featureCatalogueEntry);
}
public start(core: CoreStart, plugins: any) {