Skip to content

Commit

Permalink
Redirecting to stream if missing privileges for logs explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedhamed-ahmed committed Sep 30, 2024
1 parent 96e05f2 commit 3fe591c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ? (
<Route
path="/"
exact
render={() => {
plugins.share.url.locators
.get<AllDatasetsLocatorParams>(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
<RedirectWithQueryParams from={'/'} to={'/stream'} exact />
);

return (
<CoreProviders core={core} pluginStart={pluginStart} plugins={plugins} theme$={theme$}>
Expand All @@ -74,19 +94,9 @@ const LogsApp: React.FC<{
toastsService={core.notifications.toasts}
>
<Routes>
<Route
path="/"
exact
render={() => {
plugins.share.url.locators
.get<AllDatasetsLocatorParams>(ALL_DATASETS_LOCATOR_ID)
?.navigate({});

return null;
}}
/>
{LogsRouteComponent}
<Route path="/link-to" component={LinkToLogsPage} />
{uiCapabilities?.logs?.show && <Route path="/" component={LogsPage} />}
{logs?.show && <Route path="/" component={LogsPage} />}
</Routes>
</KbnUrlStateStorageFromRouterProvider>
</Router>
Expand Down
21 changes: 13 additions & 8 deletions x-pack/plugins/observability_solution/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -161,7 +166,7 @@ export class Plugin implements InfraClientPluginClass {
},
]
: []),
...(capabilities.infrastructure.show
...(infrastructure.show
? [
{
label: metricsTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down

0 comments on commit 3fe591c

Please sign in to comment.