diff --git a/src/plugins/maps_legacy/public/__tests__/map/service_settings.js b/src/plugins/maps_legacy/public/__tests__/map/service_settings.js index a9272ea396639..4cbe098501c67 100644 --- a/src/plugins/maps_legacy/public/__tests__/map/service_settings.js +++ b/src/plugins/maps_legacy/public/__tests__/map/service_settings.js @@ -143,24 +143,24 @@ describe('service_settings (FKA tilemaptest)', function() { } it('accepts an object', async () => { - serviceSettings.addQueryParams({ foo: 'bar' }); + serviceSettings.setQueryParams({ foo: 'bar' }); tilemapServices = await serviceSettings.getTMSServices(); await assertQuery({ foo: 'bar' }); }); it('merged additions with previous values', async () => { // ensure that changes are always additive - serviceSettings.addQueryParams({ foo: 'bar' }); - serviceSettings.addQueryParams({ bar: 'stool' }); + serviceSettings.setQueryParams({ foo: 'bar' }); + serviceSettings.setQueryParams({ bar: 'stool' }); tilemapServices = await serviceSettings.getTMSServices(); await assertQuery({ foo: 'bar', bar: 'stool' }); }); it('overwrites conflicting previous values', async () => { // ensure that conflicts are overwritten - serviceSettings.addQueryParams({ foo: 'bar' }); - serviceSettings.addQueryParams({ bar: 'stool' }); - serviceSettings.addQueryParams({ foo: 'tstool' }); + serviceSettings.setQueryParams({ foo: 'bar' }); + serviceSettings.setQueryParams({ bar: 'stool' }); + serviceSettings.setQueryParams({ foo: 'tstool' }); tilemapServices = await serviceSettings.getTMSServices(); await assertQuery({ foo: 'tstool', bar: 'stool' }); }); @@ -168,7 +168,7 @@ describe('service_settings (FKA tilemaptest)', function() { it('when overridden, should continue to work', async () => { mapConfig.emsFileApiUrl = emsFileApiUrl2; mapConfig.emsTileApiUrl = emsTileApiUrl2; - serviceSettings.addQueryParams({ foo: 'bar' }); + serviceSettings.setQueryParams({ foo: 'bar' }); tilemapServices = await serviceSettings.getTMSServices(); await assertQuery({ foo: 'bar' }); }); @@ -292,7 +292,7 @@ describe('service_settings (FKA tilemaptest)', function() { describe('File layers', function() { it('should load manifest (all props)', async function() { - serviceSettings.addQueryParams({ foo: 'bar' }); + serviceSettings.setQueryParams({ foo: 'bar' }); const fileLayers = await serviceSettings.getFileLayers(); expect(fileLayers.length).to.be(18); const assertions = fileLayers.map(async function(fileLayer) { diff --git a/src/plugins/maps_legacy/public/map/service_settings.js b/src/plugins/maps_legacy/public/map/service_settings.js index 11c853d39e107..f4f0d66ee20de 100644 --- a/src/plugins/maps_legacy/public/map/service_settings.js +++ b/src/plugins/maps_legacy/public/map/service_settings.js @@ -69,6 +69,10 @@ export class ServiceSettings { return origin === ORIGIN.EMS && this._showZoomMessage; } + enableZoomMessage() { + this._showZoomMessage = true; + } + disableZoomMessage() { this._showZoomMessage = false; } @@ -148,11 +152,12 @@ export class ServiceSettings { } /** - * Add optional query-parameters to all requests + * Set optional query-parameters for all requests * * @param additionalQueryParams */ - addQueryParams(additionalQueryParams) { + setQueryParams(additionalQueryParams) { + // Functions more as a "set" than an "add" in ems-client this._emsClient.addQueryParams(additionalQueryParams); } diff --git a/x-pack/index.js b/x-pack/index.js index 61fd4f1752316..7fbd992120ea6 100644 --- a/x-pack/index.js +++ b/x-pack/index.js @@ -9,7 +9,6 @@ import { graph } from './legacy/plugins/graph'; import { monitoring } from './legacy/plugins/monitoring'; import { reporting } from './legacy/plugins/reporting'; import { security } from './legacy/plugins/security'; -import { tilemap } from './legacy/plugins/tilemap'; import { dashboardMode } from './legacy/plugins/dashboard_mode'; import { logstash } from './legacy/plugins/logstash'; import { beats } from './legacy/plugins/beats_management'; @@ -40,7 +39,6 @@ module.exports = function(kibana) { reporting(kibana), spaces(kibana), security(kibana), - tilemap(kibana), dashboardMode(kibana), logstash(kibana), beats(kibana), diff --git a/x-pack/legacy/plugins/tilemap/index.js b/x-pack/legacy/plugins/tilemap/index.js deleted file mode 100644 index d4105519ee0a7..0000000000000 --- a/x-pack/legacy/plugins/tilemap/index.js +++ /dev/null @@ -1,31 +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. - */ - -import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status'; -import { inspectSettings } from './server/lib/inspect_settings'; -import { resolve } from 'path'; - -export const tilemap = kibana => { - return new kibana.Plugin({ - id: 'tilemap', - configPrefix: 'xpack.tilemap', - require: ['xpack_main', 'vis_type_vislib'], - publicDir: resolve(__dirname, 'public'), - uiExports: { - hacks: ['plugins/tilemap/vis_type_enhancers/update_tilemap_settings'], - }, - init: function(server) { - const thisPlugin = this; - const xpackMainPlugin = server.plugins.xpack_main; - mirrorPluginStatus(xpackMainPlugin, thisPlugin); - xpackMainPlugin.status.once('green', () => { - xpackMainPlugin.info - .feature(thisPlugin.id) - .registerLicenseCheckResultsGenerator(inspectSettings); - }); - }, - }); -}; diff --git a/x-pack/legacy/plugins/tilemap/public/vis_type_enhancers/update_tilemap_settings.js b/x-pack/legacy/plugins/tilemap/public/vis_type_enhancers/update_tilemap_settings.js deleted file mode 100644 index 294bc31e3893e..0000000000000 --- a/x-pack/legacy/plugins/tilemap/public/vis_type_enhancers/update_tilemap_settings.js +++ /dev/null @@ -1,16 +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. - */ - -import { xpackInfo } from 'plugins/xpack_main/services/xpack_info'; -import { npSetup } from 'ui/new_platform'; - -const tileMapPluginInfo = xpackInfo.get('features.tilemap'); - -if (tileMapPluginInfo && (tileMapPluginInfo.license.active || tileMapPluginInfo.license.valid)) { - const { serviceSettings } = npSetup.plugins.mapsLegacy; - serviceSettings.addQueryParams({ license: tileMapPluginInfo.license.uid }); - serviceSettings.disableZoomMessage(); -} diff --git a/x-pack/legacy/plugins/tilemap/server/lib/__tests__/inspect_settings.js b/x-pack/legacy/plugins/tilemap/server/lib/__tests__/inspect_settings.js deleted file mode 100644 index ce7987ee396b8..0000000000000 --- a/x-pack/legacy/plugins/tilemap/server/lib/__tests__/inspect_settings.js +++ /dev/null @@ -1,36 +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. - */ - -import expect from '@kbn/expect'; -import { inspectSettings } from '../../../server/lib/inspect_settings'; - -describe('inspectSettings', function() { - it('should propagate x-pack info', function() { - const mockSettings = { - isAvailable: () => true, - license: { - getUid: () => 'foobar', - isActive: () => true, - isOneOf: () => true, - }, - }; - - const licenseInfo = inspectSettings(mockSettings); - expect(licenseInfo.license.uid).to.equal('foobar'); - expect(licenseInfo.license.active).to.equal(true); - expect(licenseInfo.license.valid).to.equal(true); - }); - - it('should break when unavailable info', function() { - const mockSettings = { - isAvailable: () => false, - }; - - const licenseInfo = inspectSettings(mockSettings); - expect(licenseInfo).to.have.property('message'); - expect(typeof licenseInfo.message === 'string').to.be.ok(); - }); -}); diff --git a/x-pack/legacy/plugins/tilemap/server/lib/inspect_settings.js b/x-pack/legacy/plugins/tilemap/server/lib/inspect_settings.js deleted file mode 100644 index cd6fb8bd8c110..0000000000000 --- a/x-pack/legacy/plugins/tilemap/server/lib/inspect_settings.js +++ /dev/null @@ -1,32 +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. - */ - -export function inspectSettings(xpackInfo) { - if (!xpackInfo || !xpackInfo.isAvailable()) { - return { - message: - 'You cannot use the Tilemap Plugin because license information is not available at this time.', - }; - } - - /** - *Propagate these settings to the client - */ - return { - license: { - uid: xpackInfo.license.getUid(), - active: xpackInfo.license.isActive(), - valid: xpackInfo.license.isOneOf([ - 'trial', - 'standard', - 'basic', - 'gold', - 'platinum', - 'enterprise', - ]), - }, - }; -} diff --git a/x-pack/legacy/plugins/tilemap/README.md b/x-pack/plugins/maps_legacy_licensing/README.md similarity index 100% rename from x-pack/legacy/plugins/tilemap/README.md rename to x-pack/plugins/maps_legacy_licensing/README.md diff --git a/x-pack/plugins/maps_legacy_licensing/kibana.json b/x-pack/plugins/maps_legacy_licensing/kibana.json new file mode 100644 index 0000000000000..e98c33d21ec40 --- /dev/null +++ b/x-pack/plugins/maps_legacy_licensing/kibana.json @@ -0,0 +1,8 @@ +{ + "id": "mapsLegacyLicensing", + "version": "8.0.0", + "kibanaVersion": "kibana", + "server": false, + "ui": true, + "requiredPlugins": ["licensing", "mapsLegacy"] +} diff --git a/x-pack/plugins/maps_legacy_licensing/public/index.ts b/x-pack/plugins/maps_legacy_licensing/public/index.ts new file mode 100644 index 0000000000000..edda6118f92dd --- /dev/null +++ b/x-pack/plugins/maps_legacy_licensing/public/index.ts @@ -0,0 +1,11 @@ +/* + * 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. + */ + +import { MapsLegacyLicensing } from './plugin'; + +export function plugin() { + return new MapsLegacyLicensing(); +} diff --git a/x-pack/plugins/maps_legacy_licensing/public/plugin.ts b/x-pack/plugins/maps_legacy_licensing/public/plugin.ts new file mode 100644 index 0000000000000..69c25efd96e75 --- /dev/null +++ b/x-pack/plugins/maps_legacy_licensing/public/plugin.ts @@ -0,0 +1,49 @@ +/* + * 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. + */ + +import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; +import { LicensingPluginSetup, ILicense } from '../../licensing/public'; + +/** + * These are the interfaces with your public contracts. You should export these + * for other plugins to use in _their_ `SetupDeps`/`StartDeps` interfaces. + * @public + */ + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface MapsLegacyLicensingSetupDependencies { + licensing: LicensingPluginSetup; + mapsLegacy: any; +} +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface MapsLegacyLicensingStartDependencies {} + +export type MapsLegacyLicensingSetup = ReturnType; +export type MapsLegacyLicensingStart = ReturnType; + +export class MapsLegacyLicensing + implements Plugin { + public setup(core: CoreSetup, plugins: MapsLegacyLicensingSetupDependencies) { + const { + licensing, + mapsLegacy: { serviceSettings }, + } = plugins; + if (licensing) { + licensing.license$.subscribe((license: ILicense) => { + const { uid, isActive } = license; + if (isActive && license.hasAtLeast('basic')) { + serviceSettings.setQueryParams({ license: uid }); + serviceSettings.disableZoomMessage(); + } else { + serviceSettings.setQueryParams({ license: undefined }); + serviceSettings.enableZoomMessage(); + } + }); + } + } + + public start(core: CoreStart, plugins: MapsLegacyLicensingStartDependencies) {} +} diff --git a/x-pack/test/licensing_plugin/legacy/updates.ts b/x-pack/test/licensing_plugin/legacy/updates.ts index 5fa1299d1f285..03b61b9db87f8 100644 --- a/x-pack/test/licensing_plugin/legacy/updates.ts +++ b/x-pack/test/licensing_plugin/legacy/updates.ts @@ -50,14 +50,9 @@ export default function(ftrContext: FtrProviderContext) { await scenario.startBasic(); await scenario.waitForPluginToDetectLicenseUpdate(); - const { body: legacyBasicLicense, header: legacyBasicLicenseHeaders } = await supertest - .get('/api/xpack/v1/info') - .expect(200); + const { body: legacyBasicLicense } = await supertest.get('/api/xpack/v1/info').expect(200); expect(legacyBasicLicense.license?.type).to.be('basic'); expect(legacyBasicLicense.features).to.have.property('security'); - expect(legacyBasicLicenseHeaders['kbn-xpack-sig']).to.not.be( - legacyInitialLicenseHeaders['kbn-xpack-sig'] - ); // banner shown only when license expired not just deleted await testSubjects.missingOrFail('licenseExpiredBanner');