mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Access control: use delegatable flag to check if role can be granted (#42070)
* Access control: use delegatable flag to check if role can be granted or not * Fix naming
This commit is contained in:
parent
e7e5c54148
commit
da2c99a2e1
@ -64,6 +64,7 @@ type RoleDTO struct {
|
|||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Group string `xorm:"group_name" json:"group"`
|
Group string `xorm:"group_name" json:"group"`
|
||||||
Permissions []Permission `json:"permissions,omitempty"`
|
Permissions []Permission `json:"permissions,omitempty"`
|
||||||
|
Delegatable *bool `json:"delegatable,omitempty"`
|
||||||
|
|
||||||
ID int64 `json:"-" xorm:"pk autoincr 'id'"`
|
ID int64 `json:"-" xorm:"pk autoincr 'id'"`
|
||||||
OrgID int64 `json:"-" xorm:"org_id"`
|
OrgID int64 `json:"-" xorm:"org_id"`
|
||||||
|
@ -194,6 +194,7 @@ export const RolePickerMenu = ({
|
|||||||
key={i}
|
key={i}
|
||||||
isSelected={groupSelected(option.value) || groupPartiallySelected(option.value)}
|
isSelected={groupSelected(option.value) || groupPartiallySelected(option.value)}
|
||||||
partiallySelected={groupPartiallySelected(option.value)}
|
partiallySelected={groupPartiallySelected(option.value)}
|
||||||
|
disabled={option.options?.every(isNotDelegatable)}
|
||||||
onChange={onGroupChange}
|
onChange={onGroupChange}
|
||||||
onOpenSubMenu={onOpenSubMenu}
|
onOpenSubMenu={onOpenSubMenu}
|
||||||
onCloseSubMenu={onCloseSubMenu}
|
onCloseSubMenu={onCloseSubMenu}
|
||||||
@ -221,6 +222,7 @@ export const RolePickerMenu = ({
|
|||||||
data={option}
|
data={option}
|
||||||
key={i}
|
key={i}
|
||||||
isSelected={!!(option.uid && !!selectedOptions.find((opt) => opt.uid === option.uid))}
|
isSelected={!!(option.uid && !!selectedOptions.find((opt) => opt.uid === option.uid))}
|
||||||
|
disabled={isNotDelegatable(option)}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
hideDescription
|
hideDescription
|
||||||
/>
|
/>
|
||||||
@ -237,6 +239,7 @@ export const RolePickerMenu = ({
|
|||||||
data={option}
|
data={option}
|
||||||
key={i}
|
key={i}
|
||||||
isSelected={!!(option.uid && !!selectedOptions.find((opt) => opt.uid === option.uid))}
|
isSelected={!!(option.uid && !!selectedOptions.find((opt) => opt.uid === option.uid))}
|
||||||
|
disabled={isNotDelegatable(option)}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
hideDescription
|
hideDescription
|
||||||
/>
|
/>
|
||||||
@ -329,7 +332,9 @@ export const RolePickerSubMenu = ({
|
|||||||
disabledOptions?.find((opt) => opt.uid === option.uid))
|
disabledOptions?.find((opt) => opt.uid === option.uid))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
disabled={!!(option.uid && disabledOptions?.find((opt) => opt.uid === option.uid))}
|
disabled={
|
||||||
|
!!(option.uid && disabledOptions?.find((opt) => opt.uid === option.uid)) || isNotDelegatable(option)
|
||||||
|
}
|
||||||
onChange={onSelect}
|
onChange={onSelect}
|
||||||
hideDescription
|
hideDescription
|
||||||
/>
|
/>
|
||||||
@ -507,6 +512,10 @@ const capitalize = (s: string): string => {
|
|||||||
|
|
||||||
const sortRolesByName = (a: Role, b: Role) => a.name.localeCompare(b.name);
|
const sortRolesByName = (a: Role, b: Role) => a.name.localeCompare(b.name);
|
||||||
|
|
||||||
|
const isNotDelegatable = (role: Role) => {
|
||||||
|
return role.delegatable !== undefined && !role.delegatable;
|
||||||
|
};
|
||||||
|
|
||||||
export const getStyles = (theme: GrafanaTheme2) => {
|
export const getStyles = (theme: GrafanaTheme2) => {
|
||||||
return {
|
return {
|
||||||
menuWrapper: css`
|
menuWrapper: css`
|
||||||
|
@ -36,9 +36,9 @@ export const UserRolePicker: FC<Props> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const fetchRoleOptions = async (orgId?: number, query?: string): Promise<Role[]> => {
|
export const fetchRoleOptions = async (orgId?: number, query?: string): Promise<Role[]> => {
|
||||||
let rolesUrl = '/api/access-control/roles';
|
let rolesUrl = '/api/access-control/roles?delegatable=true';
|
||||||
if (orgId) {
|
if (orgId) {
|
||||||
rolesUrl += `?targetOrgId=${orgId}`;
|
rolesUrl += `&targetOrgId=${orgId}`;
|
||||||
}
|
}
|
||||||
const roles = await getBackendSrv().get(rolesUrl);
|
const roles = await getBackendSrv().get(rolesUrl);
|
||||||
if (!roles || !roles.length) {
|
if (!roles || !roles.length) {
|
||||||
|
@ -57,6 +57,7 @@ export interface Role {
|
|||||||
description: string;
|
description: string;
|
||||||
group: string;
|
group: string;
|
||||||
global: boolean;
|
global: boolean;
|
||||||
|
delegatable?: boolean;
|
||||||
version: number;
|
version: number;
|
||||||
created: string;
|
created: string;
|
||||||
updated: string;
|
updated: string;
|
||||||
|
Loading…
Reference in New Issue
Block a user