forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Data Frame Analytics creation: add messaging when permission req…
…uirements are not met (elastic#177720) ## Summary Fixes elastic#174125 This PR fixes the way the job creation success is checked - previously a non-error was considered a success and any returned errors were swallowed. The job creation request returns an object containing information on whether the job was created and whether there were any errors. This returned object is now checked. Now the job creation error is shown and job start is only attempted if creation is truly successful. Callouts have also been added at the config and details step if there are permission issues with the selected data views. The user can continue to use the wizard and create a usable job config but they are warned that job creation will fail due to the permission issues and are directed to docs. Configuration step when insufficient source index permission: <img width="1698" alt="image" src="https://github.com/elastic/kibana/assets/6446462/139c6f7b-e365-4b3a-bc03-7b39a359e0a6"> Details step when insufficient destination index permission: <img width="1716" alt="image" src="https://github.com/elastic/kibana/assets/6446462/a693b2cc-5797-4fba-9a22-2ca638c5c911"> Creation error now properly shown to user: <img width="1388" alt="image" src="https://github.com/elastic/kibana/assets/6446462/16268af2-6054-4e5e-a5a6-d2b43d1d61ab"> ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
- Loading branch information
1 parent
dfb31f5
commit ac3b849
Showing
10 changed files
with
163 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...on/data_frame_analytics/pages/analytics_creation/components/index_permissions_callout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { FC } from 'react'; | ||
import { EuiCallOut, EuiLink, EuiSpacer } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useMlKibana } from '../../../../contexts/kibana'; | ||
import { useHasRequiredIndicesPermissions } from '../hooks'; | ||
|
||
export const IndexPermissionsCallout: FC<{ indexName: string; docsType: 'start' | 'create' }> = ({ | ||
indexName, | ||
docsType, | ||
}) => { | ||
const { | ||
services: { | ||
docLinks: { | ||
links: { | ||
ml: { dFAStartJob, dFACreateJob }, | ||
}, | ||
}, | ||
}, | ||
} = useMlKibana(); | ||
|
||
const docsLink = docsType === 'start' ? dFAStartJob : dFACreateJob; | ||
const hasRequiredIndicesPermissions = useHasRequiredIndicesPermissions( | ||
indexName, | ||
docsType === 'start' | ||
); | ||
// If 'hasRequiredIndicesPermissions' is undefined - the index passed to the check is an empty string | ||
if (hasRequiredIndicesPermissions === undefined || hasRequiredIndicesPermissions === true) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<EuiCallOut | ||
title={i18n.translate('xpack.ml.dataframe.analytics.create.permissionsCalloutTitle', { | ||
defaultMessage: 'Indices permissions required', | ||
})} | ||
iconType="warning" | ||
color="warning" | ||
> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.ml.dataframe.analytics.create.indicesPermissionsMessage" | ||
defaultMessage="You don't have the required permissions on the {indexName} index. Refer to the {docLink} for more information on requirements." | ||
values={{ | ||
indexName, | ||
docLink: ( | ||
<EuiLink href={docsLink} target="_blank"> | ||
<FormattedMessage | ||
id="xpack.ml.dataframe.analytics.create.indicesPermissionsMessage.docsLink" | ||
defaultMessage="documentation" | ||
/> | ||
</EuiLink> | ||
), | ||
}} | ||
/> | ||
</p> | ||
</EuiCallOut> | ||
<EuiSpacer /> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...plication/data_frame_analytics/pages/analytics_creation/hooks/use_has_index_permission.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useState, useEffect } from 'react'; | ||
|
||
import { useMlKibana } from '../../../../contexts/kibana'; | ||
|
||
export const useHasRequiredIndicesPermissions = ( | ||
indexName: string, | ||
isDestIndex: boolean = false | ||
) => { | ||
const [hasIndexPermissions, setHasIndexPermissions] = useState<boolean>(true); | ||
const { | ||
services: { | ||
mlServices: { | ||
mlApiServices: { hasPrivileges }, | ||
}, | ||
}, | ||
} = useMlKibana(); | ||
|
||
useEffect( | ||
function checkRequiredIndexPermissions() { | ||
async function checkPrivileges() { | ||
const sourceIndexPriv = ['view_index_metadata']; | ||
const destIndexPriv = ['create_index', 'manage', 'index']; | ||
|
||
const privileges = await hasPrivileges({ | ||
index: [ | ||
{ | ||
names: [indexName], | ||
privileges: ['read', ...(isDestIndex ? destIndexPriv : sourceIndexPriv)], | ||
}, | ||
], | ||
}); | ||
|
||
setHasIndexPermissions(privileges.hasPrivileges?.has_all_requested === true); | ||
} | ||
|
||
checkPrivileges(); | ||
}, | ||
[hasPrivileges, indexName, isDestIndex] | ||
); | ||
|
||
if (indexName === '') { | ||
return; | ||
} | ||
|
||
return hasIndexPermissions; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters