From 02befdebd26232714e701b8040d8fa71e9fbb4fd Mon Sep 17 00:00:00 2001 From: Ryland Herrick Date: Tue, 28 Jan 2020 21:06:37 -0600 Subject: [PATCH] [SIEM] Adds ability to infer the newsfeed.enabled setting (#56236) * Always return a contract from the newsfeed plugin Without a contract, dependent plugins have no way of knowing whether the plugin is enabled or not as the contract will always be undefined. * Export newsfeed contract types from public index So that dependent plugins can use them. * Declare newsfeed as an optional dependency of SIEM We're going to use the availability of the newsfeed plugin as part of our determination for whether or not to show the security newsfeed. If users set `newsfeed.enabled: false`, the plugin will be unavailable and the security feed will not be shown. * Respect global newsfeed.enabled config in Security newsfeed The presence of the newsfeed plugin means that newsfeed.enabled is true. If both that and our local setting are true, we will show the Security feed. * Prefer object type over empty interface Co-authored-by: Elastic Machine --- src/plugins/newsfeed/public/index.ts | 4 +++- src/plugins/newsfeed/public/plugin.tsx | 10 +++++++--- .../siem/public/components/news_feed/index.tsx | 12 ++++++++---- x-pack/legacy/plugins/siem/public/plugin.tsx | 2 ++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/plugins/newsfeed/public/index.ts b/src/plugins/newsfeed/public/index.ts index 1217de60d9638..b70606b09a34f 100644 --- a/src/plugins/newsfeed/public/index.ts +++ b/src/plugins/newsfeed/public/index.ts @@ -18,7 +18,9 @@ */ import { PluginInitializerContext } from 'src/core/public'; -import { NewsfeedPublicPlugin } from './plugin'; +import { Setup, Start, NewsfeedPublicPlugin } from './plugin'; + +export { Setup, Start }; export function plugin(initializerContext: PluginInitializerContext) { return new NewsfeedPublicPlugin(initializerContext); diff --git a/src/plugins/newsfeed/public/plugin.tsx b/src/plugins/newsfeed/public/plugin.tsx index c4e042fe452f9..d21cf75a1a65e 100644 --- a/src/plugins/newsfeed/public/plugin.tsx +++ b/src/plugins/newsfeed/public/plugin.tsx @@ -27,8 +27,8 @@ import { FetchResult, NewsfeedPluginInjectedConfig } from '../types'; import { NewsfeedNavButton, NewsfeedApiFetchResult } from './components/newsfeed_header_nav_button'; import { getApi } from './lib/api'; -export type Setup = void; -export type Start = void; +export type Setup = object; +export type Start = object; export class NewsfeedPublicPlugin implements Plugin { private readonly kibanaVersion: string; @@ -38,7 +38,9 @@ export class NewsfeedPublicPlugin implements Plugin { this.kibanaVersion = initializerContext.env.packageInfo.version; } - public setup(core: CoreSetup): Setup {} + public setup(core: CoreSetup): Setup { + return {}; + } public start(core: CoreStart): Start { const api$ = this.fetchNewsfeed(core); @@ -46,6 +48,8 @@ export class NewsfeedPublicPlugin implements Plugin { order: 1000, mount: target => this.mount(api$, target), }); + + return {}; } public stop() { diff --git a/x-pack/legacy/plugins/siem/public/components/news_feed/index.tsx b/x-pack/legacy/plugins/siem/public/components/news_feed/index.tsx index 95f12758d5e63..6a5e08b287f96 100644 --- a/x-pack/legacy/plugins/siem/public/components/news_feed/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/news_feed/index.tsx @@ -8,7 +8,7 @@ import React, { useEffect, useState } from 'react'; import chrome from 'ui/chrome'; import { fetchNews, getNewsFeedUrl, getNewsItemsFromApiResponse } from './helpers'; -import { useUiSetting$ } from '../../lib/kibana'; +import { useKibana, useUiSetting$ } from '../../lib/kibana'; import { NewsFeed } from './news_feed'; import { NewsItem } from './types'; @@ -16,10 +16,14 @@ export const StatefulNewsFeed = React.memo<{ enableNewsFeedSetting: string; newsFeedSetting: string; }>(({ enableNewsFeedSetting, newsFeedSetting }) => { + const kibanaNewsfeedEnabled = useKibana().services.newsfeed; const [enableNewsFeed] = useUiSetting$(enableNewsFeedSetting); const [newsFeedUrlSetting] = useUiSetting$(newsFeedSetting); const [news, setNews] = useState(null); + // respect kibana's global newsfeed.enabled setting + const newsfeedEnabled = kibanaNewsfeedEnabled && enableNewsFeed; + const newsFeedUrl = getNewsFeedUrl({ newsFeedUrlSetting, getKibanaVersion: chrome.getKibanaVersion, @@ -42,16 +46,16 @@ export const StatefulNewsFeed = React.memo<{ } }; - if (enableNewsFeed) { + if (newsfeedEnabled) { fetchData(); } return () => { canceled = true; }; - }, [enableNewsFeed, newsFeedUrl]); + }, [newsfeedEnabled, newsFeedUrl]); - return <>{enableNewsFeed ? : null}; + return <>{newsfeedEnabled ? : null}; }); StatefulNewsFeed.displayName = 'StatefulNewsFeed'; diff --git a/x-pack/legacy/plugins/siem/public/plugin.tsx b/x-pack/legacy/plugins/siem/public/plugin.tsx index 057ed3a91c3b9..7911b5eb9833b 100644 --- a/x-pack/legacy/plugins/siem/public/plugin.tsx +++ b/x-pack/legacy/plugins/siem/public/plugin.tsx @@ -14,6 +14,7 @@ import { import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { DataPublicPluginStart } from '../../../../../src/plugins/data/public'; import { IEmbeddableStart } from '../../../../../src/plugins/embeddable/public'; +import { Start as NewsfeedStart } from '../../../../../src/plugins/newsfeed/public'; import { Start as InspectorStart } from '../../../../../src/plugins/inspector/public'; import { IUiActionsStart } from '../../../../../src/plugins/ui_actions/public'; import { UsageCollectionSetup } from '../../../../../src/plugins/usage_collection/public'; @@ -29,6 +30,7 @@ export interface StartPlugins { data: DataPublicPluginStart; embeddable: IEmbeddableStart; inspector: InspectorStart; + newsfeed?: NewsfeedStart; uiActions: IUiActionsStart; } export type StartServices = CoreStart & StartPlugins;