diff --git a/docs/development/core/public/kibana-plugin-core-public.doclinksstart.links.md b/docs/development/core/public/kibana-plugin-core-public.doclinksstart.links.md index 0e23064385a6..ff2a8a2b5f75 100644 --- a/docs/development/core/public/kibana-plugin-core-public.doclinksstart.links.md +++ b/docs/development/core/public/kibana-plugin-core-public.doclinksstart.links.md @@ -108,12 +108,38 @@ readonly links: { readonly ml: Record; readonly transforms: Record; readonly visualize: Record; - readonly apis: Record; + readonly apis: Readonly<{ + createIndex: string; + createSnapshotLifecyclePolicy: string; + createRoleMapping: string; + createRoleMappingTemplates: string; + createApiKey: string; + createPipeline: string; + createTransformRequest: string; + executeWatchActionModes: string; + openIndex: string; + putComponentTemplate: string; + painlessExecute: string; + putComponentTemplateMetadata: string; + putWatch: string; + updateTransform: string; + }>; readonly observability: Record; readonly alerting: Record; readonly maps: Record; readonly monitoring: Record; - readonly security: Record; + readonly security: Readonly<{ + apiKeyServiceSettings: string; + clusterPrivileges: string; + elasticsearchSettings: string; + elasticsearchEnableSecurity: string; + indicesPrivileges: string; + kibanaTLS: string; + kibanaPrivileges: string; + mappingRoles: string; + mappingRolesFieldRules: string; + runAsPrivilege: string; + }>; readonly watcher: Record; readonly ccs: Record; }; diff --git a/docs/development/core/public/kibana-plugin-core-public.doclinksstart.md b/docs/development/core/public/kibana-plugin-core-public.doclinksstart.md index 3ad747a42f84..8404326f773e 100644 --- a/docs/development/core/public/kibana-plugin-core-public.doclinksstart.md +++ b/docs/development/core/public/kibana-plugin-core-public.doclinksstart.md @@ -17,5 +17,5 @@ export interface DocLinksStart | --- | --- | --- | | [DOC\_LINK\_VERSION](./kibana-plugin-core-public.doclinksstart.doc_link_version.md) | string | | | [ELASTIC\_WEBSITE\_URL](./kibana-plugin-core-public.doclinksstart.elastic_website_url.md) | string | | -| [links](./kibana-plugin-core-public.doclinksstart.links.md) | {
readonly dashboard: {
readonly guide: string;
readonly drilldowns: string;
readonly drilldownsTriggerPicker: string;
readonly urlDrilldownTemplateSyntax: string;
readonly urlDrilldownVariables: string;
};
readonly filebeat: {
readonly base: string;
readonly installation: string;
readonly configuration: string;
readonly elasticsearchOutput: string;
readonly startup: string;
readonly exportedFields: string;
};
readonly auditbeat: {
readonly base: string;
};
readonly metricbeat: {
readonly base: string;
};
readonly heartbeat: {
readonly base: string;
};
readonly logstash: {
readonly base: string;
};
readonly functionbeat: {
readonly base: string;
};
readonly winlogbeat: {
readonly base: string;
};
readonly aggs: {
readonly date_histogram: string;
readonly date_range: string;
readonly date_format_pattern: string;
readonly filter: string;
readonly filters: string;
readonly geohash_grid: string;
readonly histogram: string;
readonly ip_range: string;
readonly range: string;
readonly significant_terms: string;
readonly terms: string;
readonly avg: string;
readonly avg_bucket: string;
readonly max_bucket: string;
readonly min_bucket: string;
readonly sum_bucket: string;
readonly cardinality: string;
readonly count: string;
readonly cumulative_sum: string;
readonly derivative: string;
readonly geo_bounds: string;
readonly geo_centroid: string;
readonly max: string;
readonly median: string;
readonly min: string;
readonly moving_avg: string;
readonly percentile_ranks: string;
readonly serial_diff: string;
readonly std_dev: string;
readonly sum: string;
readonly top_hits: string;
};
readonly runtimeFields: string;
readonly scriptedFields: {
readonly scriptFields: string;
readonly scriptAggs: string;
readonly painless: string;
readonly painlessApi: string;
readonly painlessSyntax: string;
readonly luceneExpressions: string;
};
readonly indexPatterns: {
readonly loadingData: string;
readonly introduction: string;
};
readonly addData: string;
readonly kibana: string;
readonly elasticsearch: Record<string, string>;
readonly siem: {
readonly guide: string;
readonly gettingStarted: string;
};
readonly query: {
readonly eql: string;
readonly luceneQuerySyntax: string;
readonly queryDsl: string;
readonly kueryQuerySyntax: string;
};
readonly date: {
readonly dateMath: string;
};
readonly management: Record<string, string>;
readonly ml: Record<string, string>;
readonly transforms: Record<string, string>;
readonly visualize: Record<string, string>;
readonly apis: Record<string, string>;
readonly observability: Record<string, string>;
readonly alerting: Record<string, string>;
readonly maps: Record<string, string>;
readonly monitoring: Record<string, string>;
readonly security: Record<string, string>;
readonly watcher: Record<string, string>;
readonly ccs: Record<string, string>;
} | | +| [links](./kibana-plugin-core-public.doclinksstart.links.md) | {
readonly dashboard: {
readonly guide: string;
readonly drilldowns: string;
readonly drilldownsTriggerPicker: string;
readonly urlDrilldownTemplateSyntax: string;
readonly urlDrilldownVariables: string;
};
readonly discover: Record<string, string>;
readonly filebeat: {
readonly base: string;
readonly installation: string;
readonly configuration: string;
readonly elasticsearchOutput: string;
readonly startup: string;
readonly exportedFields: string;
};
readonly auditbeat: {
readonly base: string;
};
readonly metricbeat: {
readonly base: string;
};
readonly heartbeat: {
readonly base: string;
};
readonly logstash: {
readonly base: string;
};
readonly functionbeat: {
readonly base: string;
};
readonly winlogbeat: {
readonly base: string;
};
readonly aggs: {
readonly date_histogram: string;
readonly date_range: string;
readonly date_format_pattern: string;
readonly filter: string;
readonly filters: string;
readonly geohash_grid: string;
readonly histogram: string;
readonly ip_range: string;
readonly range: string;
readonly significant_terms: string;
readonly terms: string;
readonly avg: string;
readonly avg_bucket: string;
readonly max_bucket: string;
readonly min_bucket: string;
readonly sum_bucket: string;
readonly cardinality: string;
readonly count: string;
readonly cumulative_sum: string;
readonly derivative: string;
readonly geo_bounds: string;
readonly geo_centroid: string;
readonly max: string;
readonly median: string;
readonly min: string;
readonly moving_avg: string;
readonly percentile_ranks: string;
readonly serial_diff: string;
readonly std_dev: string;
readonly sum: string;
readonly top_hits: string;
};
readonly runtimeFields: string;
readonly scriptedFields: {
readonly scriptFields: string;
readonly scriptAggs: string;
readonly painless: string;
readonly painlessApi: string;
readonly painlessSyntax: string;
readonly luceneExpressions: string;
};
readonly indexPatterns: {
readonly loadingData: string;
readonly introduction: string;
};
readonly addData: string;
readonly kibana: string;
readonly elasticsearch: Record<string, string>;
readonly siem: {
readonly guide: string;
readonly gettingStarted: string;
};
readonly query: {
readonly eql: string;
readonly luceneQuerySyntax: string;
readonly queryDsl: string;
readonly kueryQuerySyntax: string;
};
readonly date: {
readonly dateMath: string;
};
readonly management: Record<string, string>;
readonly ml: Record<string, string>;
readonly transforms: Record<string, string>;
readonly visualize: Record<string, string>;
readonly apis: Readonly<{
createIndex: string;
createSnapshotLifecyclePolicy: string;
createRoleMapping: string;
createRoleMappingTemplates: string;
createApiKey: string;
createPipeline: string;
createTransformRequest: string;
executeWatchActionModes: string;
openIndex: string;
putComponentTemplate: string;
painlessExecute: string;
putComponentTemplateMetadata: string;
putWatch: string;
updateTransform: string;
}>;
readonly observability: Record<string, string>;
readonly alerting: Record<string, string>;
readonly maps: Record<string, string>;
readonly monitoring: Record<string, string>;
readonly security: Readonly<{
apiKeyServiceSettings: string;
clusterPrivileges: string;
elasticsearchSettings: string;
elasticsearchEnableSecurity: string;
indicesPrivileges: string;
kibanaTLS: string;
kibanaPrivileges: string;
mappingRoles: string;
mappingRolesFieldRules: string;
runAsPrivilege: string;
}>;
readonly watcher: Record<string, string>;
readonly ccs: Record<string, string>;
} | | diff --git a/src/core/public/doc_links/doc_links_service.ts b/src/core/public/doc_links/doc_links_service.ts index 43960ce7db46..6c0ced7022cb 100644 --- a/src/core/public/doc_links/doc_links_service.ts +++ b/src/core/public/doc_links/doc_links_service.ts @@ -220,7 +220,7 @@ export class DocLinksService { }, apis: { createIndex: `${ELASTICSEARCH_DOCS}indices-create-index.html`, - createSnapshotLifecylePolicy: `${ELASTICSEARCH_DOCS}slm-api-put-policy.html`, + createSnapshotLifecyclePolicy: `${ELASTICSEARCH_DOCS}slm-api-put-policy.html`, createRoleMapping: `${ELASTICSEARCH_DOCS}security-api-put-role-mapping.html`, createRoleMappingTemplates: `${ELASTICSEARCH_DOCS}security-api-put-role-mapping.html#_role_templates`, createApiKey: `${ELASTICSEARCH_DOCS}security-api-create-api-key.html`, @@ -344,12 +344,38 @@ export interface DocLinksStart { readonly ml: Record; readonly transforms: Record; readonly visualize: Record; - readonly apis: Record; + readonly apis: Readonly<{ + createIndex: string; + createSnapshotLifecyclePolicy: string; + createRoleMapping: string; + createRoleMappingTemplates: string; + createApiKey: string; + createPipeline: string; + createTransformRequest: string; + executeWatchActionModes: string; + openIndex: string; + putComponentTemplate: string; + painlessExecute: string; + putComponentTemplateMetadata: string; + putWatch: string; + updateTransform: string; + }>; readonly observability: Record; readonly alerting: Record; readonly maps: Record; readonly monitoring: Record; - readonly security: Record; + readonly security: Readonly<{ + apiKeyServiceSettings: string; + clusterPrivileges: string; + elasticsearchSettings: string; + elasticsearchEnableSecurity: string; + indicesPrivileges: string; + kibanaTLS: string; + kibanaPrivileges: string; + mappingRoles: string; + mappingRolesFieldRules: string; + runAsPrivilege: string; + }>; readonly watcher: Record; readonly ccs: Record; }; diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index c5b49519ef7b..2f4c871c3343 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -587,12 +587,38 @@ export interface DocLinksStart { readonly ml: Record; readonly transforms: Record; readonly visualize: Record; - readonly apis: Record; + readonly apis: Readonly<{ + createIndex: string; + createSnapshotLifecyclePolicy: string; + createRoleMapping: string; + createRoleMappingTemplates: string; + createApiKey: string; + createPipeline: string; + createTransformRequest: string; + executeWatchActionModes: string; + openIndex: string; + putComponentTemplate: string; + painlessExecute: string; + putComponentTemplateMetadata: string; + putWatch: string; + updateTransform: string; + }>; readonly observability: Record; readonly alerting: Record; readonly maps: Record; readonly monitoring: Record; - readonly security: Record; + readonly security: Readonly<{ + apiKeyServiceSettings: string; + clusterPrivileges: string; + elasticsearchSettings: string; + elasticsearchEnableSecurity: string; + indicesPrivileges: string; + kibanaTLS: string; + kibanaPrivileges: string; + mappingRoles: string; + mappingRolesFieldRules: string; + runAsPrivilege: string; + }>; readonly watcher: Record; readonly ccs: Record; }; diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/__snapshots__/api_keys_grid_page.test.tsx.snap b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/__snapshots__/api_keys_grid_page.test.tsx.snap index 3c6458a6d246..44b6c081bcfb 100644 --- a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/__snapshots__/api_keys_grid_page.test.tsx.snap +++ b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/__snapshots__/api_keys_grid_page.test.tsx.snap @@ -1,132 +1,123 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`APIKeysGridPage renders a callout when API keys are not enabled 1`] = ` - } > - - } +
- - + + -
- - - , - } - } - > - Contact your system administrator and refer to the - - + +
+ + -
-
- - + (opens in a new tab or window) + + + + + + to enable API keys. + +
+ + +
`; exports[`APIKeysGridPage renders permission denied if user does not have required permissions 1`] = ` diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.test.tsx b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.test.tsx index 68daf427677f..a55d872ca60f 100644 --- a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.test.tsx +++ b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.test.tsx @@ -10,10 +10,10 @@ import { ReactWrapper } from 'enzyme'; import { EuiCallOut } from '@elastic/eui'; import type { PublicMethodsOf } from '@kbn/utility-types'; +import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; import { NotEnabled } from './not_enabled'; import { PermissionDenied } from './permission_denied'; import { APIKeysAPIClient } from '../api_keys_api_client'; -import { DocumentationLinksService } from '../documentation_links'; import { APIKeysGridPage } from './api_keys_grid_page'; import { coreMock } from '../../../../../../../src/core/public/mocks'; @@ -66,21 +66,16 @@ describe('APIKeysGridPage', () => { }); const coreStart = coreMock.createStart(); - - const getViewProperties = () => { - const { docLinks, notifications, application } = coreStart; - return { - docLinks: new DocumentationLinksService(docLinks), - navigateToApp: application.navigateToApp, - notifications, - apiKeysAPIClient: apiClientMock, - }; + const renderView = () => { + return mountWithIntl( + + + + ); }; it('renders a loading state when fetching API keys', async () => { - const wrapper = mountWithIntl(); - - expect(wrapper.find('[data-test-subj="apiKeysSectionLoading"]')).toHaveLength(1); + expect(renderView().find('[data-test-subj="apiKeysSectionLoading"]')).toHaveLength(1); }); it('renders a callout when API keys are not enabled', async () => { @@ -90,13 +85,12 @@ describe('APIKeysGridPage', () => { areApiKeysEnabled: false, }); - const wrapper = mountWithIntl(); - + const wrapper = renderView(); await waitForRender(wrapper, (updatedWrapper) => { return updatedWrapper.find(NotEnabled).length > 0; }); - expect(wrapper.find(NotEnabled)).toMatchSnapshot(); + expect(wrapper.find(NotEnabled).find(EuiCallOut)).toMatchSnapshot(); }); it('renders permission denied if user does not have required permissions', async () => { @@ -106,8 +100,7 @@ describe('APIKeysGridPage', () => { areApiKeysEnabled: true, }); - const wrapper = mountWithIntl(); - + const wrapper = renderView(); await waitForRender(wrapper, (updatedWrapper) => { return updatedWrapper.find(PermissionDenied).length > 0; }); @@ -118,8 +111,7 @@ describe('APIKeysGridPage', () => { it('renders error callout if error fetching API keys', async () => { apiClientMock.getApiKeys.mockRejectedValue(mock500()); - const wrapper = mountWithIntl(); - + const wrapper = renderView(); await waitForRender(wrapper, (updatedWrapper) => { return updatedWrapper.find(EuiCallOut).length > 0; }); @@ -130,7 +122,7 @@ describe('APIKeysGridPage', () => { describe('Admin view', () => { let wrapper: ReactWrapper; beforeEach(() => { - wrapper = mountWithIntl(); + wrapper = renderView(); }); it('renders a callout indicating the user is an administrator', async () => { @@ -165,7 +157,7 @@ describe('APIKeysGridPage', () => { areApiKeysEnabled: true, }); - wrapper = mountWithIntl(); + wrapper = renderView(); }); it('does NOT render a callout indicating the user is an administrator', async () => { diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.tsx b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.tsx index b4ea91ea024f..c208502fc6a3 100644 --- a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.tsx +++ b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.tsx @@ -28,11 +28,10 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import type { PublicMethodsOf } from '@kbn/utility-types'; import moment from 'moment-timezone'; -import { ApplicationStart, NotificationsStart } from 'src/core/public'; +import type { NotificationsStart } from 'src/core/public'; import { SectionLoading } from '../../../../../../../src/plugins/es_ui_shared/public'; import { ApiKey, ApiKeyToInvalidate } from '../../../../common/model'; import { APIKeysAPIClient } from '../api_keys_api_client'; -import { DocumentationLinksService } from '../documentation_links'; import { PermissionDenied } from './permission_denied'; import { EmptyPrompt } from './empty_prompt'; import { NotEnabled } from './not_enabled'; @@ -40,9 +39,7 @@ import { InvalidateProvider } from './invalidate_provider'; interface Props { notifications: NotificationsStart; - docLinks: DocumentationLinksService; apiKeysAPIClient: PublicMethodsOf; - navigateToApp: ApplicationStart['navigateToApp']; } interface State { @@ -132,7 +129,7 @@ export class APIKeysGridPage extends Component { if (!areApiKeysEnabled) { return ( - + ); } @@ -140,11 +137,7 @@ export class APIKeysGridPage extends Component { if (!isLoadingTable && apiKeys && apiKeys.length === 0) { return ( - + ); } diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/empty_prompt/empty_prompt.tsx b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/empty_prompt/empty_prompt.tsx index 9b2ccfcb99ef..39a34efb9f93 100644 --- a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/empty_prompt/empty_prompt.tsx +++ b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/empty_prompt/empty_prompt.tsx @@ -5,72 +5,70 @@ */ import React, { Fragment } from 'react'; -import { ApplicationStart } from 'kibana/public'; import { EuiEmptyPrompt, EuiButton, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { DocumentationLinksService } from '../../documentation_links'; +import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; interface Props { isAdmin: boolean; - docLinks: DocumentationLinksService; - navigateToApp: ApplicationStart['navigateToApp']; } -export const EmptyPrompt: React.FunctionComponent = ({ - isAdmin, - docLinks, - navigateToApp, -}) => ( - - {isAdmin ? ( +export const EmptyPrompt: React.FunctionComponent = ({ isAdmin }) => { + const { services } = useKibana(); + const application = services.application!; + const docLinks = services.docLinks!; + return ( + + {isAdmin ? ( + + ) : ( + + )} + + } + body={ + +

+ + + + ), + }} + /> +

+
+ } + actions={ + application.navigateToApp('dev_tools')} + data-test-subj="goToConsoleButton" + > - ) : ( - - )} - - } - body={ - -

- - - - ), - }} - /> -

-
- } - actions={ - navigateToApp('dev_tools')} - data-test-subj="goToConsoleButton" - > - - - } - data-test-subj="emptyPrompt" - /> -); +
+ } + data-test-subj="emptyPrompt" + /> + ); +}; diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/not_enabled/not_enabled.tsx b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/not_enabled/not_enabled.tsx index 08fe54255775..54ea724cfef1 100644 --- a/x-pack/plugins/security/public/management/api_keys/api_keys_grid/not_enabled/not_enabled.tsx +++ b/x-pack/plugins/security/public/management/api_keys/api_keys_grid/not_enabled/not_enabled.tsx @@ -7,36 +7,35 @@ import React from 'react'; import { EuiCallOut, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { DocumentationLinksService } from '../../documentation_links'; +import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; -interface Props { - docLinks: DocumentationLinksService; -} - -export const NotEnabled: React.FunctionComponent = ({ docLinks }) => ( - { + const docLinks = useKibana().services.docLinks!; + return ( + + } + color="danger" + iconType="alert" + > + + + ), + }} /> - } - color="danger" - iconType="alert" - > - - - - ), - }} - /> - -); + + ); +}; diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.test.tsx b/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.test.tsx index 2b43bc7ebc20..e9901b8f7847 100644 --- a/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.test.tsx +++ b/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.test.tsx @@ -43,7 +43,7 @@ describe('apiKeysManagementApp', () => { expect(setBreadcrumbs).toHaveBeenCalledWith([{ href: '/', text: 'API Keys' }]); expect(container).toMatchInlineSnapshot(`
- Page: {"notifications":{"toasts":{}},"docLinks":{"apiKeySettings":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-settings.html#api-key-service-settings","createApiKey":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-api-create-api-key.html"},"apiKeysAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}}} + Page: {"notifications":{"toasts":{}},"apiKeysAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}}}
`); diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.tsx b/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.tsx index 6ff91852d0a3..241bb4382881 100644 --- a/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.tsx +++ b/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.tsx @@ -9,8 +9,8 @@ import { render, unmountComponentAtNode } from 'react-dom'; import { i18n } from '@kbn/i18n'; import { StartServicesAccessor } from 'src/core/public'; import { RegisterManagementAppArgs } from '../../../../../../src/plugins/management/public'; +import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; import { PluginStartDependencies } from '../../plugin'; -import { DocumentationLinksService } from './documentation_links'; interface CreateParams { getStartServices: StartServicesAccessor; @@ -35,25 +35,21 @@ export const apiKeysManagementApp = Object.freeze({ }, ]); - const [ - [{ docLinks, http, notifications, i18n: i18nStart, application }], - { APIKeysGridPage }, - { APIKeysAPIClient }, - ] = await Promise.all([ + const [[core], { APIKeysGridPage }, { APIKeysAPIClient }] = await Promise.all([ getStartServices(), import('./api_keys_grid'), import('./api_keys_api_client'), ]); render( - - - , + + + + + , element ); diff --git a/x-pack/plugins/security/public/management/api_keys/documentation_links.ts b/x-pack/plugins/security/public/management/api_keys/documentation_links.ts deleted file mode 100644 index 66a54f1cb7b7..000000000000 --- a/x-pack/plugins/security/public/management/api_keys/documentation_links.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { DocLinksStart } from 'src/core/public'; - -export class DocumentationLinksService { - private readonly apiKeySettings: string; - private readonly createApiKey: string; - - constructor(docLinks: DocLinksStart) { - this.apiKeySettings = `${docLinks.links.security.apiKeyServiceSettings}`; - this.createApiKey = `${docLinks.links.apis.createApiKey}`; - } - - public getApiKeyServiceSettingsDocUrl() { - return `${this.apiKeySettings}`; - } - - public getCreateApiKeyDocUrl() { - return `${this.createApiKey}`; - } -} diff --git a/x-pack/plugins/security/public/management/role_mappings/components/no_compatible_realms/no_compatible_realms.tsx b/x-pack/plugins/security/public/management/role_mappings/components/no_compatible_realms/no_compatible_realms.tsx index 5e14b0c179bf..a3a7377b0d39 100644 --- a/x-pack/plugins/security/public/management/role_mappings/components/no_compatible_realms/no_compatible_realms.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/components/no_compatible_realms/no_compatible_realms.tsx @@ -7,36 +7,35 @@ import React from 'react'; import { EuiCallOut, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { DocumentationLinksService } from '../../documentation_links'; +import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; -interface Props { - docLinks: DocumentationLinksService; -} - -export const NoCompatibleRealms: React.FunctionComponent = ({ docLinks }: Props) => ( - { + const docLinks = useKibana().services.docLinks!; + return ( + + } + color="warning" + iconType="alert" + > + + + ), + }} /> - } - color="warning" - iconType="alert" - > - - - - ), - }} - /> - -); + + ); +}; diff --git a/x-pack/plugins/security/public/management/role_mappings/documentation_links.ts b/x-pack/plugins/security/public/management/role_mappings/documentation_links.ts deleted file mode 100644 index 2098d5c71ee7..000000000000 --- a/x-pack/plugins/security/public/management/role_mappings/documentation_links.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { DocLinksStart } from 'src/core/public'; - -export class DocumentationLinksService { - private readonly mappingRoles: string; - private readonly createRoleMapping: string; - private readonly createRoleMappingTemplates: string; - private readonly roleMappingFieldRules: string; - - constructor(docLinks: DocLinksStart) { - this.mappingRoles = `${docLinks.links.security.mappingRoles}`; - this.createRoleMapping = `${docLinks.links.apis.createRoleMapping}`; - this.createRoleMappingTemplates = `${docLinks.links.apis.createRoleMappingTemplates}`; - this.roleMappingFieldRules = `${docLinks.links.security.mappingRolesFieldRules}`; - } - - public getRoleMappingDocUrl() { - return `${this.mappingRoles}`; - } - - public getRoleMappingAPIDocUrl() { - return `${this.createRoleMapping}`; - } - - public getRoleMappingTemplateDocUrl() { - return `${this.createRoleMappingTemplates}`; - } - - public getRoleMappingFieldRulesDocUrl() { - return `${this.roleMappingFieldRules}`; - } -} diff --git a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/edit_role_mapping_page.test.tsx b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/edit_role_mapping_page.test.tsx index c7c40cea63e2..64ef1459a524 100644 --- a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/edit_role_mapping_page.test.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/edit_role_mapping_page.test.tsx @@ -20,7 +20,7 @@ import { VisualRuleEditor } from './rule_editor_panel/visual_rule_editor'; import { JSONRuleEditor } from './rule_editor_panel/json_rule_editor'; import { RolesAPIClient } from '../../roles'; import { Role } from '../../../../common/model'; -import { DocumentationLinksService } from '../documentation_links'; +import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; import { coreMock, scopedHistoryMock } from '../../../../../../../src/core/public/mocks'; import { roleMappingsAPIClientMock } from '../role_mappings_api_client.mock'; @@ -31,6 +31,25 @@ describe('EditRoleMappingPage', () => { const history = scopedHistoryMock.create(); let rolesAPI: PublicMethodsOf; + const renderView = ( + roleMappingsAPI: ReturnType, + name?: string + ) => { + const coreStart = coreMock.createStart(); + return mountWithIntl( + + + + ); + }; + beforeEach(() => { rolesAPI = rolesAPIClientMock.create(); (rolesAPI as jest.Mocked).getRoles.mockResolvedValue([ @@ -50,17 +69,7 @@ describe('EditRoleMappingPage', () => { canUseStoredScripts: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); - + const wrapper = renderView(roleMappingsAPI); await nextTick(); wrapper.update(); @@ -112,18 +121,7 @@ describe('EditRoleMappingPage', () => { canUseStoredScripts: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); - + const wrapper = renderView(roleMappingsAPI, 'foo'); await nextTick(); wrapper.update(); @@ -161,16 +159,7 @@ describe('EditRoleMappingPage', () => { hasCompatibleRealms: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); + const wrapper = renderView(roleMappingsAPI); expect(wrapper.find(SectionLoading)).toHaveLength(1); expect(wrapper.find(PermissionDenied)).toHaveLength(0); @@ -189,16 +178,7 @@ describe('EditRoleMappingPage', () => { hasCompatibleRealms: false, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); + const wrapper = renderView(roleMappingsAPI); expect(wrapper.find(SectionLoading)).toHaveLength(1); expect(wrapper.find(NoCompatibleRealms)).toHaveLength(0); @@ -226,18 +206,7 @@ describe('EditRoleMappingPage', () => { canUseStoredScripts: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); - + const wrapper = renderView(roleMappingsAPI, 'foo'); expect(findTestSubject(wrapper, 'deprecatedRolesAssigned')).toHaveLength(0); await nextTick(); @@ -267,18 +236,7 @@ describe('EditRoleMappingPage', () => { canUseStoredScripts: false, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); - + const wrapper = renderView(roleMappingsAPI, 'foo'); expect(findTestSubject(wrapper, 'roleMappingInlineScriptsDisabled')).toHaveLength(0); expect(findTestSubject(wrapper, 'roleMappingStoredScriptsDisabled')).toHaveLength(0); @@ -310,18 +268,7 @@ describe('EditRoleMappingPage', () => { canUseStoredScripts: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); - + const wrapper = renderView(roleMappingsAPI, 'foo'); expect(findTestSubject(wrapper, 'roleMappingInlineScriptsDisabled')).toHaveLength(0); expect(findTestSubject(wrapper, 'roleMappingStoredScriptsDisabled')).toHaveLength(0); @@ -365,18 +312,7 @@ describe('EditRoleMappingPage', () => { canUseStoredScripts: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); - + const wrapper = renderView(roleMappingsAPI, 'foo'); await nextTick(); wrapper.update(); @@ -421,18 +357,7 @@ describe('EditRoleMappingPage', () => { canUseStoredScripts: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); - + const wrapper = renderView(roleMappingsAPI, 'foo'); await nextTick(); wrapper.update(); diff --git a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/edit_role_mapping_page.tsx b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/edit_role_mapping_page.tsx index 30584348960a..3de11e84e042 100644 --- a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/edit_role_mapping_page.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/edit_role_mapping_page.tsx @@ -20,7 +20,7 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import type { PublicMethodsOf } from '@kbn/utility-types'; -import { NotificationsStart, ScopedHistory } from 'src/core/public'; +import type { NotificationsStart, ScopedHistory, DocLinksStart } from 'src/core/public'; import { RoleMapping } from '../../../../common/model'; import { RuleEditorPanel } from './rule_editor_panel'; import { @@ -32,7 +32,6 @@ import { import { RolesAPIClient } from '../../roles'; import { validateRoleMappingForSave } from './services/role_mapping_validation'; import { MappingInfoPanel } from './mapping_info_panel'; -import { DocumentationLinksService } from '../documentation_links'; import { RoleMappingsAPIClient } from '../role_mappings_api_client'; interface State { @@ -54,7 +53,7 @@ interface Props { roleMappingsAPI: PublicMethodsOf; rolesAPIClient: PublicMethodsOf; notifications: NotificationsStart; - docLinks: DocumentationLinksService; + docLinks: DocLinksStart; history: ScopedHistory; } @@ -163,7 +162,7 @@ export class EditRoleMappingPage extends Component { values={{ learnMoreLink: ( @@ -180,7 +179,7 @@ export class EditRoleMappingPage extends Component { {!this.state.hasCompatibleRealms && ( <> - + )} diff --git a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/mapping_info_panel/mapping_info_panel.test.tsx b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/mapping_info_panel/mapping_info_panel.test.tsx index dbd034ff3f76..f9201a8dbf24 100644 --- a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/mapping_info_panel/mapping_info_panel.test.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/mapping_info_panel/mapping_info_panel.test.tsx @@ -10,7 +10,6 @@ import { mountWithIntl } from '@kbn/test/jest'; import { findTestSubject } from '@kbn/test/jest'; import { Role, RoleMapping } from '../../../../../common/model'; import { RolesAPIClient } from '../../../roles'; -import { DocumentationLinksService } from '../../documentation_links'; import { RoleSelector } from '../role_selector'; import { RoleTemplateEditor } from '../role_selector/role_template_editor'; import { MappingInfoPanel } from '.'; @@ -39,7 +38,7 @@ describe('MappingInfoPanel', () => { metadata: {}, } as RoleMapping, mode: 'create', - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), + docLinks: coreMock.createStart().docLinks, rolesAPIClient: rolesAPI, } as MappingInfoPanel['props']; @@ -86,7 +85,7 @@ describe('MappingInfoPanel', () => { metadata: {}, } as RoleMapping, mode: 'edit', - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), + docLinks: coreMock.createStart().docLinks, rolesAPIClient: rolesAPI, } as MappingInfoPanel['props']; @@ -112,7 +111,7 @@ describe('MappingInfoPanel', () => { canUseInlineScripts: true, canUseStoredScripts: false, validateForm: false, - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), + docLinks: coreMock.createStart().docLinks, rolesAPIClient: rolesAPI, }; @@ -153,7 +152,7 @@ describe('MappingInfoPanel', () => { canUseInlineScripts: false, canUseStoredScripts: true, validateForm: false, - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), + docLinks: coreMock.createStart().docLinks, rolesAPIClient: rolesAPI, }; @@ -194,7 +193,7 @@ describe('MappingInfoPanel', () => { canUseInlineScripts: false, canUseStoredScripts: false, validateForm: false, - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), + docLinks: coreMock.createStart().docLinks, rolesAPIClient: rolesAPI, }; @@ -219,7 +218,7 @@ describe('MappingInfoPanel', () => { metadata: {}, } as RoleMapping, mode: 'edit', - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), + docLinks: coreMock.createStart().docLinks, rolesAPIClient: rolesAPI, } as MappingInfoPanel['props']; diff --git a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/mapping_info_panel/mapping_info_panel.tsx b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/mapping_info_panel/mapping_info_panel.tsx index faf0278e5d8f..8176950a4633 100644 --- a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/mapping_info_panel/mapping_info_panel.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/mapping_info_panel/mapping_info_panel.tsx @@ -20,6 +20,7 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import type { PublicMethodsOf } from '@kbn/utility-types'; +import type { DocLinksStart } from 'src/core/public'; import { RoleMapping } from '../../../../../common/model'; import { RolesAPIClient } from '../../../roles'; import { @@ -28,7 +29,6 @@ import { validateRoleMappingRoleTemplates, } from '../services/role_mapping_validation'; import { RoleSelector } from '../role_selector'; -import { DocumentationLinksService } from '../../documentation_links'; interface Props { roleMapping: RoleMapping; @@ -38,7 +38,7 @@ interface Props { canUseInlineScripts: boolean; canUseStoredScripts: boolean; rolesAPIClient: PublicMethodsOf; - docLinks: DocumentationLinksService; + docLinks: DocLinksStart; } interface State { @@ -205,7 +205,7 @@ export class MappingInfoPanel extends Component { defaultMessage="Create templates that describe the roles to assign to your users." />{' '} diff --git a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/json_rule_editor.test.tsx b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/json_rule_editor.test.tsx index bae41b31cdcc..5c7c6ed5b3ca 100644 --- a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/json_rule_editor.test.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/json_rule_editor.test.tsx @@ -17,20 +17,24 @@ import { act } from 'react-dom/test-utils'; import { mountWithIntl } from '@kbn/test/jest'; import { JSONRuleEditor } from './json_rule_editor'; import { EuiCodeEditor } from '@elastic/eui'; +import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public'; import { AllRule, AnyRule, FieldRule, ExceptAnyRule, ExceptAllRule } from '../../model'; -import { DocumentationLinksService } from '../../documentation_links'; import { coreMock } from '../../../../../../../../src/core/public/mocks'; describe('JSONRuleEditor', () => { + const renderView = (props: React.ComponentProps) => { + const coreStart = coreMock.createStart(); + return mountWithIntl( + + + + ); + }; + it('renders an empty rule set', () => { - const props = { - rules: null, - onChange: jest.fn(), - onValidityChange: jest.fn(), - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), - }; - const wrapper = mountWithIntl(); + const props = { rules: null, onChange: jest.fn(), onValidityChange: jest.fn() }; + const wrapper = renderView(props); expect(props.onChange).not.toHaveBeenCalled(); expect(props.onValidityChange).not.toHaveBeenCalled(); @@ -50,9 +54,8 @@ describe('JSONRuleEditor', () => { ]), onChange: jest.fn(), onValidityChange: jest.fn(), - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), }; - const wrapper = mountWithIntl(); + const wrapper = renderView(props); const { value } = wrapper.find(EuiCodeEditor).props(); expect(JSON.parse(value as string)).toEqual({ @@ -80,13 +83,8 @@ describe('JSONRuleEditor', () => { }); it('notifies when input contains invalid JSON', () => { - const props = { - rules: null, - onChange: jest.fn(), - onValidityChange: jest.fn(), - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), - }; - const wrapper = mountWithIntl(); + const props = { rules: null, onChange: jest.fn(), onValidityChange: jest.fn() }; + const wrapper = renderView(props); const allRule = JSON.stringify(new AllRule().toRaw()); act(() => { @@ -99,13 +97,8 @@ describe('JSONRuleEditor', () => { }); it('notifies when input contains an invalid rule set, even if it is valid JSON', () => { - const props = { - rules: null, - onChange: jest.fn(), - onValidityChange: jest.fn(), - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), - }; - const wrapper = mountWithIntl(); + const props = { rules: null, onChange: jest.fn(), onValidityChange: jest.fn() }; + const wrapper = renderView(props); const invalidRule = JSON.stringify({ all: [ @@ -127,13 +120,8 @@ describe('JSONRuleEditor', () => { }); it('fires onChange when a valid rule set is provided after being previously invalidated', () => { - const props = { - rules: null, - onChange: jest.fn(), - onValidityChange: jest.fn(), - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), - }; - const wrapper = mountWithIntl(); + const props = { rules: null, onChange: jest.fn(), onValidityChange: jest.fn() }; + const wrapper = renderView(props); const allRule = JSON.stringify(new AllRule().toRaw()); act(() => { diff --git a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/json_rule_editor.tsx b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/json_rule_editor.tsx index e7a9149513d2..931803ddc6ff 100644 --- a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/json_rule_editor.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/json_rule_editor.tsx @@ -11,17 +11,17 @@ import 'brace/theme/github'; import { EuiCodeEditor, EuiFormRow, EuiButton, EuiSpacer, EuiLink, EuiText } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { DocumentationLinksService } from '../../documentation_links'; import { Rule, RuleBuilderError, generateRulesFromRaw } from '../../model'; +import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; interface Props { rules: Rule | null; onChange: (updatedRules: Rule | null) => void; onValidityChange: (isValid: boolean) => void; - docLinks: DocumentationLinksService; } export const JSONRuleEditor = (props: Props) => { + const docLinks = useKibana().services.docLinks!; const [rawRules, setRawRules] = useState( JSON.stringify(props.rules ? props.rules.toRaw() : {}, null, 2) ); @@ -108,7 +108,7 @@ export const JSONRuleEditor = (props: Props) => { values={{ roleMappingAPI: ( diff --git a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/rule_editor_panel.test.tsx b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/rule_editor_panel.test.tsx index ac31900b11a6..5a44a7c05c19 100644 --- a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/rule_editor_panel.test.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/rule_editor_panel.test.tsx @@ -17,20 +17,28 @@ import '@kbn/test/target/jest/utils/stub_web_worker'; import { AllRule, FieldRule } from '../../model'; import { EuiErrorBoundary } from '@elastic/eui'; -import { DocumentationLinksService } from '../../documentation_links'; +import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public'; import { coreMock } from '../../../../../../../../src/core/public/mocks'; describe('RuleEditorPanel', () => { + const renderView = (props: Omit, 'docLinks'>) => { + const coreStart = coreMock.createStart(); + const viewProps = { ...props, docLinks: coreStart.docLinks }; + return mountWithIntl( + + + + ); + }; it('renders the visual editor when no rules are defined', () => { const props = { rawRules: {}, onChange: jest.fn(), onValidityChange: jest.fn(), validateForm: false, - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), }; - const wrapper = mountWithIntl(); + const wrapper = renderView(props); expect(wrapper.find(VisualRuleEditor)).toHaveLength(1); expect(wrapper.find(JSONRuleEditor)).toHaveLength(0); }); @@ -49,9 +57,9 @@ describe('RuleEditorPanel', () => { onChange: jest.fn(), onValidityChange: jest.fn(), validateForm: false, - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), + docLinks: coreMock.createStart().docLinks, }; - const wrapper = mountWithIntl(); + const wrapper = renderView(props); expect(wrapper.find(VisualRuleEditor)).toHaveLength(1); expect(wrapper.find(JSONRuleEditor)).toHaveLength(0); @@ -73,9 +81,8 @@ describe('RuleEditorPanel', () => { onChange: jest.fn(), onValidityChange: jest.fn(), validateForm: false, - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), }; - const wrapper = mountWithIntl(); + const wrapper = renderView(props); findTestSubject(wrapper, 'roleMappingsJSONRuleEditorButton').simulate('click'); @@ -109,9 +116,8 @@ describe('RuleEditorPanel', () => { onChange: jest.fn(), onValidityChange: jest.fn(), validateForm: false, - docLinks: new DocumentationLinksService(coreMock.createStart().docLinks), }; - const wrapper = mountWithIntl(); + const wrapper = renderView(props); wrapper.find(VisualRuleEditor).simulateError(new Error('Something awful happened here.')); diff --git a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/rule_editor_panel.tsx b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/rule_editor_panel.tsx index 6e6641caa1f3..1b5cda1df5b5 100644 --- a/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/rule_editor_panel.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/rule_editor_panel.tsx @@ -22,12 +22,12 @@ import { } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; +import type { DocLinksStart } from 'src/core/public'; import { RoleMapping } from '../../../../../common/model'; import { VisualRuleEditor } from './visual_rule_editor'; import { JSONRuleEditor } from './json_rule_editor'; import { VISUAL_MAX_RULE_DEPTH } from '../services/role_mapping_constants'; import { Rule, generateRulesFromRaw } from '../../model'; -import { DocumentationLinksService } from '../../documentation_links'; import { validateRoleMappingRules } from '../services/role_mapping_validation'; interface Props { @@ -35,7 +35,7 @@ interface Props { onChange: (rawRules: RoleMapping['rules']) => void; onValidityChange: (isValid: boolean) => void; validateForm: boolean; - docLinks: DocumentationLinksService; + docLinks: DocLinksStart; } interface State { @@ -92,7 +92,7 @@ export class RuleEditorPanel extends Component { values={{ learnMoreLink: ( @@ -215,7 +215,6 @@ export class RuleEditorPanel extends Component { rules={this.state.rules} onChange={this.onRuleChange} onValidityChange={this.onValidityChange} - docLinks={this.props.docLinks} /> ); default: diff --git a/x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/role_mappings_grid_page.test.tsx b/x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/role_mappings_grid_page.test.tsx index a8001c1b775e..05edd3a37009 100644 --- a/x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/role_mappings_grid_page.test.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/role_mappings_grid_page.test.tsx @@ -13,7 +13,7 @@ import { EmptyPrompt } from './empty_prompt'; import { findTestSubject } from '@kbn/test/jest'; import { EuiLink } from '@elastic/eui'; import { act } from '@testing-library/react'; -import { DocumentationLinksService } from '../documentation_links'; +import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; import { coreMock, scopedHistoryMock } from '../../../../../../../src/core/public/mocks'; import { roleMappingsAPIClientMock } from '../role_mappings_api_client.mock'; @@ -23,6 +23,24 @@ describe('RoleMappingsGridPage', () => { let history: ScopedHistory; let coreStart: CoreStart; + const renderView = ( + roleMappingsAPI: ReturnType, + rolesAPI: ReturnType = rolesAPIClientMock.create() + ) => { + return mountWithIntl( + + + + ); + }; + beforeEach(() => { history = scopedHistoryMock.create(); coreStart = coreMock.createStart(); @@ -36,17 +54,7 @@ describe('RoleMappingsGridPage', () => { hasCompatibleRealms: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); + const wrapper = renderView(roleMappingsAPI); expect(wrapper.find(SectionLoading)).toHaveLength(1); expect(wrapper.find(EmptyPrompt)).toHaveLength(0); @@ -65,17 +73,7 @@ describe('RoleMappingsGridPage', () => { hasCompatibleRealms: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); + const wrapper = renderView(roleMappingsAPI); expect(wrapper.find(SectionLoading)).toHaveLength(1); expect(wrapper.find(PermissionDenied)).toHaveLength(0); @@ -102,17 +100,7 @@ describe('RoleMappingsGridPage', () => { hasCompatibleRealms: false, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); + const wrapper = renderView(roleMappingsAPI); expect(wrapper.find(SectionLoading)).toHaveLength(1); expect(wrapper.find(NoCompatibleRealms)).toHaveLength(0); @@ -138,17 +126,7 @@ describe('RoleMappingsGridPage', () => { hasCompatibleRealms: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); + const wrapper = renderView(roleMappingsAPI); await nextTick(); wrapper.update(); @@ -172,17 +150,7 @@ describe('RoleMappingsGridPage', () => { hasCompatibleRealms: true, }); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); + const wrapper = renderView(roleMappingsAPI); await nextTick(); wrapper.update(); @@ -212,17 +180,7 @@ describe('RoleMappingsGridPage', () => { }, ]); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); + const wrapper = renderView(roleMappingsAPI); await nextTick(); wrapper.update(); @@ -275,17 +233,7 @@ describe('RoleMappingsGridPage', () => { }, ]); - const { docLinks, notifications } = coreMock.createStart(); - const wrapper = mountWithIntl( - - ); + const wrapper = renderView(roleMappingsAPI, roleAPIClient); await nextTick(); wrapper.update(); diff --git a/x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/role_mappings_grid_page.tsx b/x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/role_mappings_grid_page.tsx index 7e83c3654cac..2d225f5ebd08 100644 --- a/x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/role_mappings_grid_page.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/role_mappings_grid/role_mappings_grid_page.tsx @@ -25,7 +25,12 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import type { PublicMethodsOf } from '@kbn/utility-types'; -import { NotificationsStart, ApplicationStart, ScopedHistory } from 'src/core/public'; +import type { + NotificationsStart, + ApplicationStart, + DocLinksStart, + ScopedHistory, +} from 'src/core/public'; import { RoleMapping, Role } from '../../../../common/model'; import { EmptyPrompt } from './empty_prompt'; import { @@ -35,7 +40,6 @@ import { SectionLoading, } from '../components'; import { EDIT_ROLE_MAPPING_PATH, getEditRoleMappingHref } from '../../management_urls'; -import { DocumentationLinksService } from '../documentation_links'; import { RoleMappingsAPIClient } from '../role_mappings_api_client'; import { RoleTableDisplay } from '../../role_table_display'; import { RolesAPIClient } from '../../roles'; @@ -46,7 +50,7 @@ interface Props { rolesAPIClient: PublicMethodsOf; roleMappingsAPI: PublicMethodsOf; notifications: NotificationsStart; - docLinks: DocumentationLinksService; + docLinks: DocLinksStart; history: ScopedHistory; navigateToApp: ApplicationStart['navigateToApp']; } @@ -148,7 +152,7 @@ export class RoleMappingsGridPage extends Component { values={{ learnMoreLink: ( @@ -179,7 +183,7 @@ export class RoleMappingsGridPage extends Component { {!this.state.hasCompatibleRealms && ( <> - + )} diff --git a/x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.test.tsx b/x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.test.tsx index c72aeac5ba6f..0d7443bad5f3 100644 --- a/x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.test.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.test.tsx @@ -5,11 +5,21 @@ */ jest.mock('./role_mappings_grid', () => ({ - RoleMappingsGridPage: (props: any) => `Role Mappings Page: ${JSON.stringify(props)}`, + RoleMappingsGridPage: (props: any) => + // `docLinks` object is too big to include into test snapshot, so we just check its existence. + `Role Mappings Page: ${JSON.stringify({ + ...props, + docLinks: props.docLinks ? {} : undefined, + })}`, })); jest.mock('./edit_role_mapping', () => ({ - EditRoleMappingPage: (props: any) => `Role Mapping Edit Page: ${JSON.stringify(props)}`, + EditRoleMappingPage: (props: any) => + // `docLinks` object is too big to include into test snapshot, so we just check its existence. + `Role Mapping Edit Page: ${JSON.stringify({ + ...props, + docLinks: props.docLinks ? {} : undefined, + })}`, })); import { roleMappingsManagementApp } from './role_mappings_management_app'; @@ -54,7 +64,7 @@ describe('roleMappingsManagementApp', () => { expect(setBreadcrumbs).toHaveBeenCalledWith([{ href: `/`, text: 'Role Mappings' }]); expect(container).toMatchInlineSnapshot(`
- Role Mappings Page: {"notifications":{"toasts":{}},"rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"roleMappingsAPI":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"docLinks":{"mappingRoles":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/mapping-roles.html","createRoleMapping":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-api-put-role-mapping.html","createRoleMappingTemplates":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-api-put-role-mapping.html#_role_templates","roleMappingFieldRules":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/role-mapping-resources.html#mapping-roles-rule-field"},"history":{"action":"PUSH","length":1,"location":{"pathname":"/","search":"","hash":""}}} + Role Mappings Page: {"notifications":{"toasts":{}},"rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"roleMappingsAPI":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"docLinks":{},"history":{"action":"PUSH","length":1,"location":{"pathname":"/","search":"","hash":""}}}
`); @@ -73,7 +83,7 @@ describe('roleMappingsManagementApp', () => { ]); expect(container).toMatchInlineSnapshot(`
- Role Mapping Edit Page: {"roleMappingsAPI":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"notifications":{"toasts":{}},"docLinks":{"mappingRoles":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/mapping-roles.html","createRoleMapping":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-api-put-role-mapping.html","createRoleMappingTemplates":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-api-put-role-mapping.html#_role_templates","roleMappingFieldRules":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/role-mapping-resources.html#mapping-roles-rule-field"},"history":{"action":"PUSH","length":1,"location":{"pathname":"/edit","search":"","hash":""}}} + Role Mapping Edit Page: {"roleMappingsAPI":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"notifications":{"toasts":{}},"docLinks":{},"history":{"action":"PUSH","length":1,"location":{"pathname":"/edit","search":"","hash":""}}}
`); @@ -94,7 +104,7 @@ describe('roleMappingsManagementApp', () => { ]); expect(container).toMatchInlineSnapshot(`
- Role Mapping Edit Page: {"name":"role@mapping","roleMappingsAPI":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"notifications":{"toasts":{}},"docLinks":{"mappingRoles":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/mapping-roles.html","createRoleMapping":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-api-put-role-mapping.html","createRoleMappingTemplates":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-api-put-role-mapping.html#_role_templates","roleMappingFieldRules":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/role-mapping-resources.html#mapping-roles-rule-field"},"history":{"action":"PUSH","length":1,"location":{"pathname":"/edit/role@mapping","search":"","hash":""}}} + Role Mapping Edit Page: {"name":"role@mapping","roleMappingsAPI":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"notifications":{"toasts":{}},"docLinks":{},"history":{"action":"PUSH","length":1,"location":{"pathname":"/edit/role@mapping","search":"","hash":""}}}
`); diff --git a/x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.tsx b/x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.tsx index ce4ded5a9acb..28b452c10c23 100644 --- a/x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.tsx +++ b/x-pack/plugins/security/public/management/role_mappings/role_mappings_management_app.tsx @@ -11,8 +11,8 @@ import { i18n } from '@kbn/i18n'; import { StartServicesAccessor } from 'src/core/public'; import { RegisterManagementAppArgs } from '../../../../../../src/plugins/management/public'; import { PluginStartDependencies } from '../../plugin'; -import { DocumentationLinksService } from './documentation_links'; import { tryDecodeURIComponent } from '../url_utils'; +import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; interface CreateParams { getStartServices: StartServicesAccessor; @@ -39,7 +39,7 @@ export const roleMappingsManagementApp = Object.freeze({ ]; const [ - [{ docLinks, http, notifications, i18n: i18nStart }], + [core], { RoleMappingsGridPage }, { EditRoleMappingPage }, { RoleMappingsAPIClient }, @@ -52,16 +52,15 @@ export const roleMappingsManagementApp = Object.freeze({ import('../roles'), ]); - const roleMappingsAPIClient = new RoleMappingsAPIClient(http); - const dockLinksService = new DocumentationLinksService(docLinks); + const roleMappingsAPIClient = new RoleMappingsAPIClient(core.http); const RoleMappingsGridPageWithBreadcrumbs = () => { setBreadcrumbs(roleMappingsBreadcrumbs); return ( @@ -90,27 +89,29 @@ export const roleMappingsManagementApp = Object.freeze({ ); }; render( - - - - - - - - - - - - , + + + + + + + + + + + + + + , element ); diff --git a/x-pack/plugins/security/public/management/roles/documentation_links.ts b/x-pack/plugins/security/public/management/roles/documentation_links.ts deleted file mode 100644 index aa19fbecb9c7..000000000000 --- a/x-pack/plugins/security/public/management/roles/documentation_links.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { DocLinksStart } from 'src/core/public'; - -export class DocumentationLinksService { - private readonly esClusterPrivileges: string; - private readonly esRunAsPrivilege: string; - private readonly esIndicesPrivileges: string; - - constructor(docLinks: DocLinksStart) { - this.esClusterPrivileges = `${docLinks.links.security.clusterPrivileges}`; - this.esRunAsPrivilege = `${docLinks.links.security.runAsPrivilege}`; - this.esIndicesPrivileges = `${docLinks.links.security.indicesPrivileges}`; - } - - public getESClusterPrivilegesDocUrl() { - return `${this.esClusterPrivileges}`; - } - - public getESRunAsPrivilegesDocUrl() { - return `${this.esRunAsPrivilege}`; - } - - public getESIndicesPrivilegesDocUrl() { - return `${this.esIndicesPrivileges}`; - } -} diff --git a/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.test.tsx b/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.test.tsx index b86fa1f175e9..e431b49bf2f8 100644 --- a/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.test.tsx +++ b/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.test.tsx @@ -11,7 +11,6 @@ import { mountWithIntl, nextTick } from '@kbn/test/jest'; import { Capabilities } from 'src/core/public'; import { KibanaFeature } from '../../../../../features/public'; import { Role } from '../../../../common/model'; -import { DocumentationLinksService } from '../documentation_links'; import { EditRolePage } from './edit_role_page'; import { SimplePrivilegeSection } from './privileges/kibana/simple_privilege_section'; @@ -184,7 +183,7 @@ function getProps({ userAPIClient, getFeatures: () => Promise.resolve(buildFeatures()), notifications, - docLinks: new DocumentationLinksService(docLinks), + docLinks, fatalErrors, uiCapabilities: buildUICapabilities(canManageSpaces), history: scopedHistoryMock.create(), diff --git a/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.tsx b/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.tsx index d24191c54bd9..c750ec373b9f 100644 --- a/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.tsx +++ b/x-pack/plugins/security/public/management/roles/edit_role/edit_role_page.tsx @@ -38,7 +38,7 @@ import { IHttpFetchError, NotificationsStart, } from 'src/core/public'; -import { ScopedHistory } from 'kibana/public'; +import type { DocLinksStart, ScopedHistory } from 'kibana/public'; import { FeaturesPluginStart } from '../../../../../features/public'; import { KibanaFeature } from '../../../../../features/common'; import { IndexPatternsContract } from '../../../../../../../src/plugins/data/public'; @@ -61,7 +61,6 @@ import { ElasticsearchPrivileges, KibanaPrivilegesRegion } from './privileges'; import { ReservedRoleBadge } from './reserved_role_badge'; import { SecurityLicense } from '../../../../common/licensing'; import { UserAPIClient } from '../../users'; -import { DocumentationLinksService } from '../documentation_links'; import { IndicesAPIClient } from '../indices_api_client'; import { RolesAPIClient } from '../roles_api_client'; import { PrivilegesAPIClient } from '../privileges_api_client'; @@ -77,7 +76,7 @@ interface Props { rolesAPIClient: PublicMethodsOf; privilegesAPIClient: PublicMethodsOf; getFeatures: FeaturesPluginStart['getFeatures']; - docLinks: DocumentationLinksService; + docLinks: DocLinksStart; http: HttpStart; license: SecurityLicense; uiCapabilities: Capabilities; diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/es/elasticsearch_privileges.test.tsx b/x-pack/plugins/security/public/management/roles/edit_role/privileges/es/elasticsearch_privileges.test.tsx index 316822f7db02..4a29c5a5b134 100644 --- a/x-pack/plugins/security/public/management/roles/edit_role/privileges/es/elasticsearch_privileges.test.tsx +++ b/x-pack/plugins/security/public/management/roles/edit_role/privileges/es/elasticsearch_privileges.test.tsx @@ -6,7 +6,6 @@ import React from 'react'; import { mountWithIntl, shallowWithIntl } from '@kbn/test/jest'; -import { DocumentationLinksService } from '../../../documentation_links'; import { RoleValidator } from '../../validate_role'; import { ClusterPrivileges } from './cluster_privileges'; import { ElasticsearchPrivileges } from './elasticsearch_privileges'; @@ -45,7 +44,7 @@ function getProps() { index: ['all', 'read', 'write', 'index'], }, indicesAPIClient: indicesAPIClientMock.create(), - docLinks: new DocumentationLinksService(docLinks), + docLinks, license, }; } diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/es/elasticsearch_privileges.tsx b/x-pack/plugins/security/public/management/roles/edit_role/privileges/es/elasticsearch_privileges.tsx index 8fc09ce16740..ca7a08663905 100644 --- a/x-pack/plugins/security/public/management/roles/edit_role/privileges/es/elasticsearch_privileges.tsx +++ b/x-pack/plugins/security/public/management/roles/edit_role/privileges/es/elasticsearch_privileges.tsx @@ -19,6 +19,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import type { PublicMethodsOf } from '@kbn/utility-types'; import React, { Component, Fragment } from 'react'; +import type { DocLinksStart } from 'src/core/public'; import { Role, BuiltinESPrivileges } from '../../../../../../common/model'; import { SecurityLicense } from '../../../../../../common/licensing'; import { IndicesAPIClient } from '../../../indices_api_client'; @@ -26,13 +27,12 @@ import { RoleValidator } from '../../validate_role'; import { CollapsiblePanel } from '../../collapsible_panel'; import { ClusterPrivileges } from './cluster_privileges'; import { IndexPrivileges } from './index_privileges'; -import { DocumentationLinksService } from '../../../documentation_links'; interface Props { role: Role; editable: boolean; indicesAPIClient: PublicMethodsOf; - docLinks: DocumentationLinksService; + docLinks: DocLinksStart; license: SecurityLicense; onChange: (role: Role) => void; runAsUsers: string[]; @@ -90,7 +90,7 @@ export class ElasticsearchPrivileges extends Component { id="xpack.security.management.editRole.elasticSearchPrivileges.manageRoleActionsDescription" defaultMessage="Manage the actions this role can perform against your cluster. " /> - {this.learnMore(docLinks.getESClusterPrivilegesDocUrl())} + {this.learnMore(docLinks.links.security.clusterPrivileges)}

} > @@ -120,7 +120,7 @@ export class ElasticsearchPrivileges extends Component { id="xpack.security.management.editRole.elasticSearchPrivileges.howToBeSubmittedOnBehalfOfOtherUsersDescription" defaultMessage="Allow requests to be submitted on the behalf of other users. " /> - {this.learnMore(docLinks.getESRunAsPrivilegesDocUrl())} + {this.learnMore(docLinks.links.security.runAsPrivilege)}

} > @@ -164,7 +164,7 @@ export class ElasticsearchPrivileges extends Component { id="xpack.security.management.editRole.elasticSearchPrivileges.controlAccessToClusterDataDescription" defaultMessage="Control access to the data in your cluster. " /> - {this.learnMore(docLinks.getESIndicesPrivilegesDocUrl())} + {this.learnMore(docLinks.links.security.indicesPrivileges)}

diff --git a/x-pack/plugins/security/public/management/roles/roles_management_app.test.tsx b/x-pack/plugins/security/public/management/roles/roles_management_app.test.tsx index 8003b21f5d90..12c1951fc60f 100644 --- a/x-pack/plugins/security/public/management/roles/roles_management_app.test.tsx +++ b/x-pack/plugins/security/public/management/roles/roles_management_app.test.tsx @@ -11,7 +11,9 @@ jest.mock('./roles_grid', () => ({ })); jest.mock('./edit_role', () => ({ - EditRolePage: (props: any) => `Role Edit Page: ${JSON.stringify(props)}`, + // `docLinks` object is too big to include into test snapshot, so we just check its existence. + EditRolePage: (props: any) => + `Role Edit Page: ${JSON.stringify({ ...props, docLinks: props.docLinks ? {} : undefined })}`, })); import { rolesManagementApp } from './roles_management_app'; @@ -87,7 +89,7 @@ describe('rolesManagementApp', () => { expect(setBreadcrumbs).toHaveBeenCalledWith([{ href: `/`, text: 'Roles' }, { text: 'Create' }]); expect(container).toMatchInlineSnapshot(`
- Role Edit Page: {"action":"edit","rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"userAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"indicesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"privilegesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}},"notifications":{"toasts":{}},"fatalErrors":{},"license":{"features$":{"_isScalar":false}},"docLinks":{"esClusterPrivileges":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-privileges.html#privileges-list-cluster","esRunAsPrivilege":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-privileges.html#_run_as_privilege","esIndicesPrivileges":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-privileges.html#privileges-list-indices"},"uiCapabilities":{"catalogue":{},"management":{},"navLinks":{}},"history":{"action":"PUSH","length":1,"location":{"pathname":"/edit","search":"","hash":""}}} + Role Edit Page: {"action":"edit","rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"userAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"indicesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"privilegesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}},"notifications":{"toasts":{}},"fatalErrors":{},"license":{"features$":{"_isScalar":false}},"docLinks":{},"uiCapabilities":{"catalogue":{},"management":{},"navLinks":{}},"history":{"action":"PUSH","length":1,"location":{"pathname":"/edit","search":"","hash":""}}}
`); @@ -108,7 +110,7 @@ describe('rolesManagementApp', () => { ]); expect(container).toMatchInlineSnapshot(`
- Role Edit Page: {"action":"edit","roleName":"role@name","rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"userAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"indicesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"privilegesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}},"notifications":{"toasts":{}},"fatalErrors":{},"license":{"features$":{"_isScalar":false}},"docLinks":{"esClusterPrivileges":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-privileges.html#privileges-list-cluster","esRunAsPrivilege":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-privileges.html#_run_as_privilege","esIndicesPrivileges":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-privileges.html#privileges-list-indices"},"uiCapabilities":{"catalogue":{},"management":{},"navLinks":{}},"history":{"action":"PUSH","length":1,"location":{"pathname":"/edit/role@name","search":"","hash":""}}} + Role Edit Page: {"action":"edit","roleName":"role@name","rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"userAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"indicesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"privilegesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}},"notifications":{"toasts":{}},"fatalErrors":{},"license":{"features$":{"_isScalar":false}},"docLinks":{},"uiCapabilities":{"catalogue":{},"management":{},"navLinks":{}},"history":{"action":"PUSH","length":1,"location":{"pathname":"/edit/role@name","search":"","hash":""}}}
`); @@ -126,7 +128,7 @@ describe('rolesManagementApp', () => { expect(setBreadcrumbs).toHaveBeenCalledWith([{ href: `/`, text: 'Roles' }, { text: 'Create' }]); expect(container).toMatchInlineSnapshot(`
- Role Edit Page: {"action":"clone","roleName":"someRoleName","rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"userAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"indicesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"privilegesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}},"notifications":{"toasts":{}},"fatalErrors":{},"license":{"features$":{"_isScalar":false}},"docLinks":{"esClusterPrivileges":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-privileges.html#privileges-list-cluster","esRunAsPrivilege":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-privileges.html#_run_as_privilege","esIndicesPrivileges":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/security-privileges.html#privileges-list-indices"},"uiCapabilities":{"catalogue":{},"management":{},"navLinks":{}},"history":{"action":"PUSH","length":1,"location":{"pathname":"/clone/someRoleName","search":"","hash":""}}} + Role Edit Page: {"action":"clone","roleName":"someRoleName","rolesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"userAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"indicesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"privilegesAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}}},"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{},"externalUrl":{}},"notifications":{"toasts":{}},"fatalErrors":{},"license":{"features$":{"_isScalar":false}},"docLinks":{},"uiCapabilities":{"catalogue":{},"management":{},"navLinks":{}},"history":{"action":"PUSH","length":1,"location":{"pathname":"/clone/someRoleName","search":"","hash":""}}}
`); diff --git a/x-pack/plugins/security/public/management/roles/roles_management_app.tsx b/x-pack/plugins/security/public/management/roles/roles_management_app.tsx index d5b3b4998a09..26c679516b46 100644 --- a/x-pack/plugins/security/public/management/roles/roles_management_app.tsx +++ b/x-pack/plugins/security/public/management/roles/roles_management_app.tsx @@ -12,7 +12,6 @@ import { StartServicesAccessor, FatalErrorsSetup } from 'src/core/public'; import { RegisterManagementAppArgs } from '../../../../../../src/plugins/management/public'; import { SecurityLicense } from '../../../common/licensing'; import { PluginStartDependencies } from '../../plugin'; -import { DocumentationLinksService } from './documentation_links'; import { tryDecodeURIComponent } from '../url_utils'; interface CreateParams { @@ -97,7 +96,7 @@ export const rolesManagementApp = Object.freeze({ notifications={notifications} fatalErrors={fatalErrors} license={license} - docLinks={new DocumentationLinksService(docLinks)} + docLinks={docLinks} uiCapabilities={application.capabilities} indexPatterns={data.indexPatterns} history={history} diff --git a/x-pack/plugins/security/public/security_checkup/components/insecure_cluster_alert.tsx b/x-pack/plugins/security/public/security_checkup/components/insecure_cluster_alert.tsx index 310caeac91dc..844444c0e64d 100644 --- a/x-pack/plugins/security/public/security_checkup/components/insecure_cluster_alert.tsx +++ b/x-pack/plugins/security/public/security_checkup/components/insecure_cluster_alert.tsx @@ -7,7 +7,7 @@ import React, { useState } from 'react'; import { i18n } from '@kbn/i18n'; import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; import { render, unmountComponentAtNode } from 'react-dom'; -import { MountPoint } from 'kibana/public'; +import type { DocLinksStart, MountPoint } from 'kibana/public'; import { EuiCheckbox, EuiText, @@ -16,7 +16,6 @@ import { EuiFlexItem, EuiButton, } from '@elastic/eui'; -import { DocumentationLinksService } from '../documentation_links'; export const insecureClusterAlertTitle = i18n.translate( 'xpack.security.checkup.insecureClusterTitle', @@ -24,12 +23,15 @@ export const insecureClusterAlertTitle = i18n.translate( ); export const insecureClusterAlertText = ( - getDocLinksService: () => DocumentationLinksService, + getDocLinks: () => DocLinksStart, onDismiss: (persist: boolean) => void ) => ((e) => { const AlertText = () => { const [persist, setPersist] = useState(false); + const enableSecurityDocLink = `${ + getDocLinks().links.security.elasticsearchEnableSecurity + }?blade=kibanasecuritymessage`; return ( @@ -56,7 +58,7 @@ export const insecureClusterAlertText = ( size="s" color="primary" fill - href={getDocLinksService().getEnableSecurityDocUrl()} + href={enableSecurityDocLink} target="_blank" data-test-subj="learnMoreButton" > diff --git a/x-pack/plugins/security/public/security_checkup/documentation_links.ts b/x-pack/plugins/security/public/security_checkup/documentation_links.ts deleted file mode 100644 index 4a2a2bc968cc..000000000000 --- a/x-pack/plugins/security/public/security_checkup/documentation_links.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { DocLinksStart } from 'src/core/public'; - -export class DocumentationLinksService { - private readonly esEnableSecurity: string; - - constructor(docLinks: DocLinksStart) { - this.esEnableSecurity = `${docLinks.links.security.elasticsearchEnableSecurity}`; - } - - public getEnableSecurityDocUrl() { - return `${this.esEnableSecurity}?blade=kibanasecuritymessage`; - } -} diff --git a/x-pack/plugins/security/public/security_checkup/security_checkup_service.tsx b/x-pack/plugins/security/public/security_checkup/security_checkup_service.tsx index a0ea194170df..bda9f210b02e 100644 --- a/x-pack/plugins/security/public/security_checkup/security_checkup_service.tsx +++ b/x-pack/plugins/security/public/security_checkup/security_checkup_service.tsx @@ -4,14 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import { DocLinksStart } from 'kibana/public'; +import type { DocLinksStart } from 'kibana/public'; import { SecurityOssPluginSetup, SecurityOssPluginStart, } from '../../../../../src/plugins/security_oss/public'; import { insecureClusterAlertTitle, insecureClusterAlertText } from './components'; -import { DocumentationLinksService } from './documentation_links'; interface SetupDeps { securityOssSetup: SecurityOssPluginSetup; @@ -25,13 +24,13 @@ interface StartDeps { export class SecurityCheckupService { private securityOssStart?: SecurityOssPluginStart; - private docLinksService?: DocumentationLinksService; + private docLinks?: DocLinksStart; public setup({ securityOssSetup }: SetupDeps) { securityOssSetup.insecureCluster.setAlertTitle(insecureClusterAlertTitle); securityOssSetup.insecureCluster.setAlertText( insecureClusterAlertText( - () => this.docLinksService!, + () => this.docLinks!, (persist: boolean) => this.onDismiss(persist) ) ); @@ -39,7 +38,7 @@ export class SecurityCheckupService { public start({ securityOssStart, docLinks }: StartDeps) { this.securityOssStart = securityOssStart; - this.docLinksService = new DocumentationLinksService(docLinks); + this.docLinks = docLinks; } private onDismiss(persist: boolean) {