From d3ce128556319e2d65be4d38c6c8e264e376bafa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Wed, 9 Jun 2021 12:27:53 +0200 Subject: [PATCH] [APM] Only register items in side nav if user has permissions to see app (#101707) --- x-pack/plugins/apm/public/plugin.ts | 109 +++++++++--------- .../translations/translations/ja-JP.json | 3 - .../translations/translations/zh-CN.json | 3 - 3 files changed, 54 insertions(+), 61 deletions(-) diff --git a/x-pack/plugins/apm/public/plugin.ts b/x-pack/plugins/apm/public/plugin.ts index 24db9e0cd8504..bfc0a3daf6f0e 100644 --- a/x-pack/plugins/apm/public/plugin.ts +++ b/x-pack/plugins/apm/public/plugin.ts @@ -6,7 +6,8 @@ */ import { i18n } from '@kbn/i18n'; -import { of } from 'rxjs'; +import { from } from 'rxjs'; +import { map } from 'rxjs/operators'; import type { ConfigSchema } from '.'; import { AppMountParameters, @@ -86,19 +87,56 @@ export class ApmPlugin implements Plugin { pluginSetupDeps.home.featureCatalogue.register(featureCatalogueEntry); } - // register observability nav + const servicesTitle = i18n.translate('xpack.apm.navigation.servicesTitle', { + defaultMessage: 'Services', + }); + const tracesTitle = i18n.translate('xpack.apm.navigation.tracesTitle', { + defaultMessage: 'Traces', + }); + const serviceMapTitle = i18n.translate( + 'xpack.apm.navigation.serviceMapTitle', + { defaultMessage: 'Service Map' } + ); + + // register observability nav if user has access to plugin plugins.observability.navigation.registerSections( - of([ - { - label: 'APM', - sortKey: 200, - entries: [ - { label: 'Services', app: 'apm', path: '/services' }, - { label: 'Traces', app: 'apm', path: '/traces' }, - { label: 'Service Map', app: 'apm', path: '/service-map' }, - ], - }, - ]) + from(core.getStartServices()).pipe( + map(([coreStart]) => { + if (coreStart.application.capabilities.apm.show) { + return [ + // APM navigation + { + label: 'APM', + sortKey: 200, + entries: [ + { label: servicesTitle, app: 'apm', path: '/services' }, + { label: tracesTitle, app: 'apm', path: '/traces' }, + { label: serviceMapTitle, app: 'apm', path: '/service-map' }, + ], + }, + + // UX navigation + { + label: 'User Experience', + sortKey: 201, + entries: [ + { + label: i18n.translate('xpack.apm.ux.overview.heading', { + defaultMessage: 'Overview', + }), + app: 'ux', + path: '/', + matchFullPath: true, + ignoreTrailingSlash: true, + }, + ], + }, + ]; + } + + return []; + }) + ) ); const getApmDataHelper = async () => { @@ -150,26 +188,6 @@ export class ApmPlugin implements Plugin { }, }); - plugins.observability.navigation.registerSections( - of([ - { - label: 'User Experience', - sortKey: 201, - entries: [ - { - label: i18n.translate('xpack.apm.ux.overview.heading', { - defaultMessage: 'Overview', - }), - app: 'ux', - path: '/', - matchFullPath: true, - ignoreTrailingSlash: true, - }, - ], - }, - ]) - ); - core.application.register({ id: 'apm', title: 'APM', @@ -178,29 +196,10 @@ export class ApmPlugin implements Plugin { appRoute: '/app/apm', icon: 'plugins/apm/public/icon.svg', category: DEFAULT_APP_CATEGORIES.observability, - // !! Need to be kept in sync with the routes in x-pack/plugins/apm/public/components/app/Main/route_config/index.tsx deepLinks: [ - { - id: 'services', - title: i18n.translate('xpack.apm.breadcrumb.servicesTitle', { - defaultMessage: 'Services', - }), - path: '/services', - }, - { - id: 'traces', - title: i18n.translate('xpack.apm.breadcrumb.tracesTitle', { - defaultMessage: 'Traces', - }), - path: '/traces', - }, - { - id: 'service-map', - title: i18n.translate('xpack.apm.breadcrumb.serviceMapTitle', { - defaultMessage: 'Service Map', - }), - path: '/service-map', - }, + { id: 'services', title: servicesTitle, path: '/services' }, + { id: 'traces', title: tracesTitle, path: '/traces' }, + { id: 'service-map', title: serviceMapTitle, path: '/service-map' }, ], async mount(appMountParameters: AppMountParameters) { diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index a909207d7848a..0e4855503c88b 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -5390,9 +5390,6 @@ "xpack.apm.apply.label": "適用", "xpack.apm.applyFilter": "{title} フィルターを適用", "xpack.apm.applyOptions": "オプションを適用", - "xpack.apm.breadcrumb.serviceMapTitle": "サービスマップ", - "xpack.apm.breadcrumb.servicesTitle": "サービス", - "xpack.apm.breadcrumb.tracesTitle": "トレース", "xpack.apm.chart.annotation.version": "バージョン", "xpack.apm.chart.cpuSeries.processAverageLabel": "プロセス平均", "xpack.apm.chart.cpuSeries.processMaxLabel": "プロセス最大", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index b4f27d2677efa..562fc1b426252 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -5419,9 +5419,6 @@ "xpack.apm.apply.label": "应用", "xpack.apm.applyFilter": "应用 {title} 筛选", "xpack.apm.applyOptions": "应用选项", - "xpack.apm.breadcrumb.serviceMapTitle": "服务地图", - "xpack.apm.breadcrumb.servicesTitle": "服务", - "xpack.apm.breadcrumb.tracesTitle": "追溯", "xpack.apm.chart.annotation.version": "版本", "xpack.apm.chart.cpuSeries.processAverageLabel": "进程平均值", "xpack.apm.chart.cpuSeries.processMaxLabel": "进程最大值",