Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Disable button in logstash output based on correct privileges #195210

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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 { getLogstashPipeline, LOGSTASH_CONFIG_PIPELINES } from './helpers';
import { useLogstashApiKey } from './hooks';
Expand Down Expand Up @@ -64,7 +64,8 @@ export const LogstashInstructions = () => {

const CollapsibleCallout: React.FunctionComponent<EuiCallOutProps> = ({ children, ...props }) => {
const [isOpen, setIsOpen] = useState(false);

const authz = useAuthz();
const hasAllSettings = authz.fleet.allSettings;
return (
<EuiCallOut {...props}>
<EuiSpacer size="s" />
Expand All @@ -76,7 +77,7 @@ const CollapsibleCallout: React.FunctionComponent<EuiCallOutProps> = ({ children
/>
</EuiButton>
) : (
<EuiButton onClick={() => setIsOpen(true)} fill={true}>
<EuiButton onClick={() => setIsOpen(true)} fill={true} disabled={!hasAllSettings}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I added a MissingPrivilegesToolTip in #195185 that you can use to display a tooltip on why it's disabled

<FormattedMessage
id="xpack.fleet.settings.logstashInstructions.viewInstructionButtonLabel"
defaultMessage="View steps"
Expand All @@ -96,6 +97,8 @@ const CollapsibleCallout: React.FunctionComponent<EuiCallOutProps> = ({ children
const LogstashInstructionSteps = () => {
const { docLinks } = useStartServices();
const logstashApiKey = useLogstashApiKey();
const authz = useAuthz();
const hasAllSettings = authz.fleet.allSettings;

const steps = useMemo(
() => [
Expand All @@ -120,6 +123,7 @@ const LogstashInstructionSteps = () => {
onClick={copy}
iconType="copyClipboard"
color="text"
disabled={!hasAllSettings}
aria-label={i18n.translate(
'xpack.fleet.settings.logstashInstructions.copyApiKeyButtonLabel',
{
Expand All @@ -136,6 +140,7 @@ const LogstashInstructionSteps = () => {
<EuiButton
isLoading={logstashApiKey.isLoading}
onClick={logstashApiKey.generateApiKey}
disabled={!hasAllSettings}
>
<FormattedMessage
id="xpack.fleet.settings.logstashInstructions.generateApiKeyButtonLabel"
Expand Down Expand Up @@ -214,7 +219,7 @@ const LogstashInstructionSteps = () => {
),
},
],
[logstashApiKey, docLinks]
[logstashApiKey, docLinks, hasAllSettings]
);

return (
Expand Down
Loading