Skip to content

Commit

Permalink
[Stream] Fix callout privileges (elastic#198030)
Browse files Browse the repository at this point in the history
closes elastic#197044
closes elastic#197988

## 📝  Summary

The PR targets fixing 3 bugs:

1. The callout shouldn't be shown if `Logs Explorer` isn't available,
otherwise the link displayed in the callout will cause a problem. [Fix
here](https://github.com/elastic/kibana/pull/198030/files#diff-8c5f793d1bf0d933c73047f31ded8a5a65f91e4f8d5230fc4e40dfb9b245fec1R66)
2. The callout shouldn't be shown if `Logs Explorer` is available but
the user doesn't have privilege to access it, otherwise we end up in
`Application Not Found` page. [Fix
here](https://github.com/elastic/kibana/pull/198030/files#diff-8c5f793d1bf0d933c73047f31ded8a5a65f91e4f8d5230fc4e40dfb9b245fec1R66)
3. The side nav entry for `Logs Explorer` should be hidden if `Logs
Explorer` is disabled. [Fix
here](https://github.com/elastic/kibana/pull/198030/files#diff-ad4e42fbe4d2a7a99ec5d52fbf127ded12f0efe02a10e3afa0409b40be1f4bcfR397)

(cherry picked from commit 5576316)

# Conflicts:
#	x-pack/plugins/observability_solution/infra/public/plugin.ts
  • Loading branch information
mohamedhamed-ahmed committed Oct 30, 2024
1 parent c0ef3f7 commit bcd368c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,37 @@ import { EuiCallOut } from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiButton } from '@elastic/eui';
import { AllDatasetsLocatorParams, ALL_DATASETS_LOCATOR_ID } from '@kbn/deeplinks-observability';
import {
AllDatasetsLocatorParams,
ALL_DATASETS_LOCATOR_ID,
DatasetLocatorParams,
} from '@kbn/deeplinks-observability';
import { getRouterLinkProps } from '@kbn/router-utils';
import useLocalStorage from 'react-use/lib/useLocalStorage';

import { euiThemeVars } from '@kbn/ui-theme';
import { css } from '@emotion/css';
import { SharePublicStart } from '@kbn/share-plugin/public/plugin';
import { LocatorPublic } from '@kbn/share-plugin/common';
import { useKibanaContextForPlugin } from '../hooks/use_kibana';

const DISMISSAL_STORAGE_KEY = 'log_stream_deprecation_callout_dismissed';

export const LogsDeprecationCallout = () => {
const {
services: { share },
services: {
share,
application: {
capabilities: { discover, fleet },
},
},
} = useKibanaContextForPlugin();

const [isDismissed, setDismissed] = useLocalStorage(DISMISSAL_STORAGE_KEY, false);

if (isDismissed) {
const allDatasetLocator =
share.url.locators.get<AllDatasetsLocatorParams>(ALL_DATASETS_LOCATOR_ID);

if (isDismissed || !(allDatasetLocator && discover?.show && fleet?.read)) {
return null;
}

Expand All @@ -52,7 +64,7 @@ export const LogsDeprecationCallout = () => {
fill
data-test-subj="infraLogsDeprecationCalloutTryLogsExplorerButton"
color="warning"
{...getLogsExplorerLinkProps(share)}
{...getLogsExplorerLinkProps(allDatasetLocator)}
>
{i18n.translate('xpack.infra.logsDeprecationCallout.tryLogsExplorerButtonLabel', {
defaultMessage: 'Try Logs Explorer',
Expand All @@ -62,9 +74,7 @@ export const LogsDeprecationCallout = () => {
);
};

const getLogsExplorerLinkProps = (share: SharePublicStart) => {
const locator = share.url.locators.get<AllDatasetsLocatorParams>(ALL_DATASETS_LOCATOR_ID)!;

const getLogsExplorerLinkProps = (locator: LocatorPublic<DatasetLocatorParams>) => {
return getRouterLinkProps({
href: locator.getRedirectUrl({}),
onClick: () => locator.navigate({}),
Expand Down
28 changes: 21 additions & 7 deletions x-pack/plugins/observability_solution/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import {
DEFAULT_APP_CATEGORIES,
PluginInitializerContext,
AppDeepLinkLocations,
AppStatus,
} from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { enableInfrastructureHostsView } from '@kbn/observability-plugin/public';
import { ObservabilityTriggerId } from '@kbn/observability-shared-plugin/common';
import { BehaviorSubject, combineLatest, from } from 'rxjs';
import { map } from 'rxjs';
import { BehaviorSubject, combineLatest, from, map } from 'rxjs';
import type { EmbeddableApiContext } from '@kbn/presentation-publishing';
import { apiCanAddNewPanel } from '@kbn/presentation-containers';
import { IncompatibleActionError, ADD_PANEL_TRIGGER } from '@kbn/ui-actions-plugin/public';
import { COMMON_EMBEDDABLE_GROUPING } from '@kbn/embeddable-plugin/public';
import { OBSERVABILITY_LOGS_EXPLORER_APP_ID } from '@kbn/deeplinks-observability/constants';
import type { InfraPublicConfig } from '../common/plugin_config_types';
import { createInventoryMetricRuleType } from './alerting/inventory';
import { createLogThresholdRuleType } from './alerting/log_threshold';
Expand Down Expand Up @@ -118,29 +119,29 @@ export class Plugin implements InfraClientPluginClass {
([
[
{
application: { capabilities },
application,
},
],
isInfrastructureHostsViewEnabled,
]) => {
const { infrastructure, logs, discover, fleet } = capabilities;
const { infrastructure, logs } = application.capabilities;
return [
...(logs.show
? [
{
label: 'Logs',
sortKey: 200,
entries: [
...(discover?.show && fleet?.read
? [
...(getLogsExplorerAccessibility$(application).subscribe((isAccessible) =>
isAccessible ? [
{
label: 'Explorer',
app: 'observability-logs-explorer',
path: '/',
isBetaFeature: true,
},
]
: []),
: [])),
...(this.config.featureFlags.logsUIEnabled
? [
{ label: 'Stream', app: 'logs', path: '/stream' },
Expand Down Expand Up @@ -450,3 +451,16 @@ export class Plugin implements InfraClientPluginClass {

stop() {}
}

const getLogsExplorerAccessibility$ = (application: CoreStart['application']) => {
const { capabilities, applications$ } = application;
return applications$.pipe(
map(
(apps) =>
(apps.get(OBSERVABILITY_LOGS_EXPLORER_APP_ID)?.status ?? AppStatus.inaccessible) ===
AppStatus.accessible &&
capabilities.discover?.show &&
capabilities.fleet?.read
)
);
};

0 comments on commit bcd368c

Please sign in to comment.