From 7f6ce76a84b4894c8da7850a7ddd489e4b84eac2 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 4 Mar 2020 12:03:14 -0700 Subject: [PATCH] [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 --- x-pack/legacy/plugins/maps/check_license.js | 38 ------------------- .../embeddable/map_embeddable_factory.js | 3 ++ x-pack/legacy/plugins/maps/public/plugin.ts | 20 +++++----- 3 files changed, 14 insertions(+), 47 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/check_license.js diff --git a/x-pack/legacy/plugins/maps/check_license.js b/x-pack/legacy/plugins/maps/check_license.js deleted file mode 100644 index 9e5397ee5dc7..000000000000 --- a/x-pack/legacy/plugins/maps/check_license.js +++ /dev/null @@ -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(), - }; -} diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js index ec3a588d3627..73f222615493 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js @@ -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; diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 51bec872a1c9..c3f90d815239 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -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 { - 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) {