mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 15:42:13 +08:00
Access: Disable role none option if advanced access control is not enabled (#107378)
* disable role none option if advanced access control is not enabled * filter out None instead * fix lint
This commit is contained in:
@ -1,15 +1,11 @@
|
|||||||
import { SelectableValue } from '@grafana/data';
|
import { SelectableValue } from '@grafana/data';
|
||||||
import { Trans } from '@grafana/i18n';
|
import { Trans } from '@grafana/i18n';
|
||||||
import { Icon, RadioButtonList, Tooltip, useStyles2, useTheme2, PopoverContent } from '@grafana/ui';
|
import { Icon, RadioButtonList, Tooltip, useStyles2, useTheme2, PopoverContent } from '@grafana/ui';
|
||||||
|
import { contextSrv } from 'app/core/core';
|
||||||
import { OrgRole } from 'app/types';
|
import { OrgRole } from 'app/types';
|
||||||
|
|
||||||
import { getStyles } from './styles';
|
import { getStyles } from './styles';
|
||||||
|
|
||||||
const BasicRoleOption: Array<SelectableValue<OrgRole>> = Object.values(OrgRole).map((r) => ({
|
|
||||||
label: r === OrgRole.None ? 'No basic role' : r,
|
|
||||||
value: r,
|
|
||||||
}));
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
value?: OrgRole;
|
value?: OrgRole;
|
||||||
onChange: (value: OrgRole) => void;
|
onChange: (value: OrgRole) => void;
|
||||||
@ -22,6 +18,20 @@ export const BuiltinRoleSelector = ({ value, onChange, disabled, disabledMesssag
|
|||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
|
|
||||||
|
// Create options dynamically to filter out OrgRole.None when access control is not licensed
|
||||||
|
const basicRoleOptions: Array<SelectableValue<OrgRole>> = Object.values(OrgRole)
|
||||||
|
.filter((r) => {
|
||||||
|
// Filter out OrgRole.None if access control is not licensed
|
||||||
|
if (r === OrgRole.None && !contextSrv.licensedAccessControlEnabled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.map((r) => ({
|
||||||
|
label: r === OrgRole.None ? 'No basic role' : r,
|
||||||
|
value: r,
|
||||||
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={styles.groupHeader}>
|
<div className={styles.groupHeader}>
|
||||||
@ -42,7 +52,7 @@ export const BuiltinRoleSelector = ({ value, onChange, disabled, disabledMesssag
|
|||||||
<RadioButtonList
|
<RadioButtonList
|
||||||
name="Basic Role Selector"
|
name="Basic Role Selector"
|
||||||
className={styles.basicRoleSelector}
|
className={styles.basicRoleSelector}
|
||||||
options={BasicRoleOption}
|
options={basicRoleOptions}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
Reference in New Issue
Block a user