From 3fe591ce770ced6ff7b6d076819a7b748af51559 Mon Sep 17 00:00:00 2001 From: mohamedhamed-ahmed Date: Mon, 30 Sep 2024 17:05:30 +0200 Subject: [PATCH] Redirecting to stream if missing privileges for logs explorer --- .../infra/public/apps/logs_app.tsx | 36 ++++++++++++------- .../infra/public/plugin.ts | 21 ++++++----- .../public/plugin.ts | 4 +-- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/observability_solution/infra/public/apps/logs_app.tsx b/x-pack/plugins/observability_solution/infra/public/apps/logs_app.tsx index 8bd243b0723d5..48cbbd79167a1 100644 --- a/x-pack/plugins/observability_solution/infra/public/apps/logs_app.tsx +++ b/x-pack/plugins/observability_solution/infra/public/apps/logs_app.tsx @@ -19,6 +19,7 @@ import { InfraClientStartDeps, InfraClientStartExports } from '../types'; import { CommonInfraProviders, CoreProviders } from './common_providers'; import { prepareMountElement } from './common_styles'; import { KbnUrlStateStorageFromRouterProvider } from '../containers/kbn_url_state_context'; +import { RedirectWithQueryParams } from '../utils/redirect_with_query_params'; export const renderApp = ( core: CoreStart, @@ -57,7 +58,26 @@ const LogsApp: React.FC<{ storage: Storage; theme$: AppMountParameters['theme$']; }> = ({ core, history, pluginStart, plugins, setHeaderActionMenu, storage, theme$ }) => { - const uiCapabilities = core.application.capabilities; + const { logs, discover, fleet } = core.application.capabilities; + + const LogsRouteComponent = + discover?.show && fleet?.read ? ( + { + plugins.share.url.locators + .get(ALL_DATASETS_LOCATOR_ID) + ?.navigate({}); + + return null; + }} + /> + ) : ( + // This needs to redirect to /categories once stream is deprecated when the below ticket is implemented + // https://github.com/elastic/kibana/issues/193321 + + ); return ( @@ -74,19 +94,9 @@ const LogsApp: React.FC<{ toastsService={core.notifications.toasts} > - { - plugins.share.url.locators - .get(ALL_DATASETS_LOCATOR_ID) - ?.navigate({}); - - return null; - }} - /> + {LogsRouteComponent} - {uiCapabilities?.logs?.show && } + {logs?.show && } diff --git a/x-pack/plugins/observability_solution/infra/public/plugin.ts b/x-pack/plugins/observability_solution/infra/public/plugin.ts index cb04cb1bce3eb..843a23bdfccc5 100644 --- a/x-pack/plugins/observability_solution/infra/public/plugin.ts +++ b/x-pack/plugins/observability_solution/infra/public/plugin.ts @@ -137,19 +137,24 @@ export class Plugin implements InfraClientPluginClass { ], isInfrastructureHostsViewEnabled, ]) => { + const { infrastructure, logs, discover, fleet } = capabilities; return [ - ...(capabilities.logs.show + ...(logs.show ? [ { label: 'Logs', sortKey: 200, entries: [ - { - label: 'Explorer', - app: 'observability-logs-explorer', - path: '/', - isBetaFeature: true, - }, + ...(discover?.show && fleet?.read + ? [ + { + label: 'Explorer', + app: 'observability-logs-explorer', + path: '/', + isBetaFeature: true, + }, + ] + : []), ...(this.config.featureFlags.logsUIEnabled ? [ { label: 'Stream', app: 'logs', path: '/stream' }, @@ -161,7 +166,7 @@ export class Plugin implements InfraClientPluginClass { }, ] : []), - ...(capabilities.infrastructure.show + ...(infrastructure.show ? [ { label: metricsTitle, diff --git a/x-pack/plugins/observability_solution/observability_logs_explorer/public/plugin.ts b/x-pack/plugins/observability_solution/observability_logs_explorer/public/plugin.ts index 937ec79e92f4c..798a03da0ebdf 100644 --- a/x-pack/plugins/observability_solution/observability_logs_explorer/public/plugin.ts +++ b/x-pack/plugins/observability_solution/observability_logs_explorer/public/plugin.ts @@ -129,9 +129,9 @@ export class ObservabilityLogsExplorerPlugin } public start(core: CoreStart, _pluginsStart: ObservabilityLogsExplorerStartDeps) { - const { discover, fleet } = core.application.capabilities; + const { discover, fleet, logs } = core.application.capabilities; - if (!(discover?.show && fleet?.read)) { + if (!(discover?.show && fleet?.read && logs?.show)) { this.appStateUpdater.next(() => ({ status: AppStatus.inaccessible, visibleIn: [],