Skip to content

Commit

Permalink
[8.x] [Fleet] Disable button in logstash output based on correct priv…
Browse files Browse the repository at this point in the history
…ileges (#195210) (#195275)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] Disable button in logstash output based on correct privileges
(#195210)](#195210)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Cristina
Amico","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-07T14:57:08Z","message":"[Fleet]
Disable button in logstash output based on correct privileges
(#195210)\n\nFixes
https://github.com/elastic/kibana/issues/191951\r\n\r\n##
Summary\r\nDisable button in logstash output based on correct
privileges.\r\n\r\n### Testing \r\n- Enable feature flag
`subfeaturePrivileges`\r\n- Follow testing steps in above ticket\r\nThe
button \"view steps\" in logstash output should be disabled if
role\r\ndoesn'thave `fleet.allSettings` privileges\r\n\r\n![Screenshot
2024-10-07 at 12
03\r\n25](https://github.com/user-attachments/assets/4933fa97-612c-4ddf-abcb-9838b110df09)\r\n\r\n![Screenshot
2024-10-07 at 14
48\r\n45](https://github.com/user-attachments/assets/0155480a-a7c5-4274-ab95-57a867b2a1cc)\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"71c8d6fddcb5abd32ece23c0b0c74a766691ca34","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","v8.16.0","backport:version"],"title":"[Fleet]
Disable button in logstash output based on correct
privileges","number":195210,"url":"https://github.com/elastic/kibana/pull/195210","mergeCommit":{"message":"[Fleet]
Disable button in logstash output based on correct privileges
(#195210)\n\nFixes
https://github.com/elastic/kibana/issues/191951\r\n\r\n##
Summary\r\nDisable button in logstash output based on correct
privileges.\r\n\r\n### Testing \r\n- Enable feature flag
`subfeaturePrivileges`\r\n- Follow testing steps in above ticket\r\nThe
button \"view steps\" in logstash output should be disabled if
role\r\ndoesn'thave `fleet.allSettings` privileges\r\n\r\n![Screenshot
2024-10-07 at 12
03\r\n25](https://github.com/user-attachments/assets/4933fa97-612c-4ddf-abcb-9838b110df09)\r\n\r\n![Screenshot
2024-10-07 at 14
48\r\n45](https://github.com/user-attachments/assets/0155480a-a7c5-4274-ab95-57a867b2a1cc)\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"71c8d6fddcb5abd32ece23c0b0c74a766691ca34"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195210","number":195210,"mergeCommit":{"message":"[Fleet]
Disable button in logstash output based on correct privileges
(#195210)\n\nFixes
https://github.com/elastic/kibana/issues/191951\r\n\r\n##
Summary\r\nDisable button in logstash output based on correct
privileges.\r\n\r\n### Testing \r\n- Enable feature flag
`subfeaturePrivileges`\r\n- Follow testing steps in above ticket\r\nThe
button \"view steps\" in logstash output should be disabled if
role\r\ndoesn'thave `fleet.allSettings` privileges\r\n\r\n![Screenshot
2024-10-07 at 12
03\r\n25](https://github.com/user-attachments/assets/4933fa97-612c-4ddf-abcb-9838b110df09)\r\n\r\n![Screenshot
2024-10-07 at 14
48\r\n45](https://github.com/user-attachments/assets/0155480a-a7c5-4274-ab95-57a867b2a1cc)\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"71c8d6fddcb5abd32ece23c0b0c74a766691ca34"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Cristina Amico <[email protected]>
  • Loading branch information
kibanamachine and criamico authored Oct 7, 2024
1 parent d120e66 commit db6dcbd
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -64,7 +65,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,12 +78,17 @@ const CollapsibleCallout: React.FunctionComponent<EuiCallOutProps> = ({ children
/>
</EuiButton>
) : (
<EuiButton onClick={() => setIsOpen(true)} fill={true}>
<FormattedMessage
id="xpack.fleet.settings.logstashInstructions.viewInstructionButtonLabel"
defaultMessage="View steps"
/>
</EuiButton>
<MissingPrivilegesToolTip
missingPrivilege={!hasAllSettings ? 'Settings All' : undefined}
position="left"
>
<EuiButton onClick={() => setIsOpen(true)} fill={true} disabled={!hasAllSettings}>
<FormattedMessage
id="xpack.fleet.settings.logstashInstructions.viewInstructionButtonLabel"
defaultMessage="View steps"
/>
</EuiButton>
</MissingPrivilegesToolTip>
)}
{isOpen && (
<>
Expand All @@ -96,6 +103,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 +129,7 @@ const LogstashInstructionSteps = () => {
onClick={copy}
iconType="copyClipboard"
color="text"
disabled={!hasAllSettings}
aria-label={i18n.translate(
'xpack.fleet.settings.logstashInstructions.copyApiKeyButtonLabel',
{
Expand All @@ -136,6 +146,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 +225,7 @@ const LogstashInstructionSteps = () => {
),
},
],
[logstashApiKey, docLinks]
[logstashApiKey, docLinks, hasAllSettings]
);

return (
Expand Down

0 comments on commit db6dcbd

Please sign in to comment.