Disallow deletion of restricted user attributes (#2734)
This commit is contained in:
parent
68e8a6fefc
commit
f14dd1f86e
2 changed files with 14 additions and 2 deletions
|
@ -20,11 +20,13 @@ export type Field<T> = {
|
|||
cellRenderer?: (row: T) => ReactNode;
|
||||
};
|
||||
|
||||
export type Action<T> = IAction & { isActionable?: (item: T) => boolean };
|
||||
|
||||
type DraggableTableProps<T> = Omit<TableComposableProps, "data" | "ref"> & {
|
||||
keyField: string;
|
||||
columns: Field<T>[];
|
||||
data: T[];
|
||||
actions?: IAction[];
|
||||
actions?: Action<T>[];
|
||||
onDragFinish: (dragged: string, newOrder: string[]) => void;
|
||||
};
|
||||
|
||||
|
@ -217,7 +219,14 @@ export function DraggableTable<T>({
|
|||
))}
|
||||
{actions && (
|
||||
<Td isActionCell>
|
||||
<ActionsColumn items={actions} rowData={row} />
|
||||
<ActionsColumn
|
||||
items={actions.map(({ isActionable, ...action }) =>
|
||||
isActionable
|
||||
? { ...action, isDisabled: !isActionable(row) }
|
||||
: action
|
||||
)}
|
||||
rowData={row}
|
||||
/>
|
||||
</Td>
|
||||
)}
|
||||
</Tr>
|
||||
|
|
|
@ -24,6 +24,8 @@ import { toAttribute } from "../routes/Attribute";
|
|||
import type { UserProfileAttribute } from "@keycloak/keycloak-admin-client/lib/defs/userProfileConfig";
|
||||
import useToggle from "../../utils/useToggle";
|
||||
|
||||
const RESTRICTED_ATTRIBUTES = ["username", "email"];
|
||||
|
||||
type movedAttributeType = UserProfileAttribute;
|
||||
|
||||
export const AttributesTab = () => {
|
||||
|
@ -182,6 +184,7 @@ export const AttributesTab = () => {
|
|||
},
|
||||
{
|
||||
title: t("common:delete"),
|
||||
isActionable: ({ name }) => !RESTRICTED_ATTRIBUTES.includes(name!),
|
||||
onClick: (_key, _idx, component) => {
|
||||
setAttributeToDelete(component.name);
|
||||
toggleDeleteDialog();
|
||||
|
|
Loading…
Reference in a new issue