[UII] Only show beta integrations setting for settings write privilege (#187513)

## Summary

Resolves [#184639](https://github.com/elastic/kibana/issues/184639).

This PR hides the beta integrations toggle if user does not have
sufficient privileges to write this to Fleet settings SO. The real fix
should be handled with #187511.
This commit is contained in:
Jen Huang 2024-07-04 01:07:31 -07:00 committed by GitHub
parent 22c05b7b59
commit 3dfcb859c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,7 +23,7 @@ import {
EuiSwitch,
} from '@elastic/eui';
import { usePutSettingsMutation, useStartServices } from '../../../hooks';
import { usePutSettingsMutation, useStartServices, useAuthz } from '../../../hooks';
export type IntegrationPreferenceType = 'recommended' | 'beats' | 'agent';
@ -92,7 +92,7 @@ export const IntegrationPreference = ({
const [prereleaseIntegrationsChecked, setPrereleaseIntegrationsChecked] = React.useState<
boolean | undefined
>(undefined);
const authz = useAuthz();
const { docLinks, notifications } = useStartServices();
const { mutateAsync: mutateSettingsAsync } = usePutSettingsMutation();
@ -153,18 +153,24 @@ export const IntegrationPreference = ({
updateSettings(event.target.checked);
};
const canUpdateBetaSetting = authz.fleet.allSettings;
return (
<EuiPanel hasShadow={false} paddingSize="none">
<EuiSwitchNoWrap
label="Display beta integrations"
checked={
typeof prereleaseIntegrationsChecked !== 'undefined'
? prereleaseIntegrationsChecked
: prereleaseIntegrationsEnabled
}
onChange={onPrereleaseSwitchChange}
/>
<EuiSpacer size="l" />
{canUpdateBetaSetting && (
<>
<EuiSwitchNoWrap
label="Display beta integrations"
checked={
typeof prereleaseIntegrationsChecked !== 'undefined'
? prereleaseIntegrationsChecked
: prereleaseIntegrationsEnabled
}
onChange={onPrereleaseSwitchChange}
/>
<EuiSpacer size="l" />
</>
)}
<EuiText size="s">{title}</EuiText>
<EuiSpacer size="m" />
<EuiForm>