From 71c8d6fddcb5abd32ece23c0b0c74a766691ca34 Mon Sep 17 00:00:00 2001 From: Cristina Amico Date: Mon, 7 Oct 2024 16:57:08 +0200 Subject: [PATCH] [Fleet] Disable button in logstash output based on correct privileges (#195210) Fixes https://github.com/elastic/kibana/issues/191951 ## Summary Disable button in logstash output based on correct privileges. ### Testing - Enable feature flag `subfeaturePrivileges` - Follow testing steps in above ticket The button "view steps" in logstash output should be disabled if role doesn'thave `fleet.allSettings` privileges ![Screenshot 2024-10-07 at 12 03 25](https://github.com/user-attachments/assets/4933fa97-612c-4ddf-abcb-9838b110df09) ![Screenshot 2024-10-07 at 14 48 45](https://github.com/user-attachments/assets/0155480a-a7c5-4274-ab95-57a867b2a1cc) ### Checklist - [ ] [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 --------- Co-authored-by: Elastic Machine --- .../logstash_instructions/index.tsx | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/logstash_instructions/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/logstash_instructions/index.tsx index 675aa6cdfd28c..b03d4cb700530 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/logstash_instructions/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/logstash_instructions/index.tsx @@ -21,7 +21,8 @@ import type { EuiCallOutProps } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; -import { useStartServices } from '../../../../hooks'; +import { useStartServices, useAuthz } from '../../../../hooks'; +import { MissingPrivilegesToolTip } from '../../../../../../components/missing_privileges_tooltip'; import { getLogstashPipeline, LOGSTASH_CONFIG_PIPELINES } from './helpers'; import { useLogstashApiKey } from './hooks'; @@ -64,7 +65,8 @@ export const LogstashInstructions = () => { const CollapsibleCallout: React.FunctionComponent = ({ children, ...props }) => { const [isOpen, setIsOpen] = useState(false); - + const authz = useAuthz(); + const hasAllSettings = authz.fleet.allSettings; return ( @@ -76,12 +78,17 @@ const CollapsibleCallout: React.FunctionComponent = ({ children /> ) : ( - setIsOpen(true)} fill={true}> - - + + setIsOpen(true)} fill={true} disabled={!hasAllSettings}> + + + )} {isOpen && ( <> @@ -96,6 +103,8 @@ const CollapsibleCallout: React.FunctionComponent = ({ children const LogstashInstructionSteps = () => { const { docLinks } = useStartServices(); const logstashApiKey = useLogstashApiKey(); + const authz = useAuthz(); + const hasAllSettings = authz.fleet.allSettings; const steps = useMemo( () => [ @@ -120,6 +129,7 @@ const LogstashInstructionSteps = () => { onClick={copy} iconType="copyClipboard" color="text" + disabled={!hasAllSettings} aria-label={i18n.translate( 'xpack.fleet.settings.logstashInstructions.copyApiKeyButtonLabel', { @@ -136,6 +146,7 @@ const LogstashInstructionSteps = () => { { ), }, ], - [logstashApiKey, docLinks] + [logstashApiKey, docLinks, hasAllSettings] ); return (