Skip to content

Commit

Permalink
[APM] Only register items in side nav if user has permissions to see app
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Jun 9, 2021
1 parent 12986fb commit f97019c
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { i18n } from '@kbn/i18n';
import { of } from 'rxjs';
import { of, from, pipe } from 'rxjs';
import { map } from 'rxjs/operators';
import type { ConfigSchema } from '.';
import {
AppMountParameters,
Expand Down Expand Up @@ -86,19 +87,45 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
pluginSetupDeps.home.featureCatalogue.register(featureCatalogueEntry);
}

// register observability nav
// 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: 'Services', app: 'apm', path: '/services' },
{ label: 'Traces', app: 'apm', path: '/traces' },
{ label: 'Service Map', 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 () => {
Expand Down Expand Up @@ -150,26 +177,6 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
},
});

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',
Expand Down

0 comments on commit f97019c

Please sign in to comment.