Skip to content

Commit

Permalink
UI changes to not delete root user
Browse files Browse the repository at this point in the history
  • Loading branch information
pjdotson committed Sep 26, 2024
1 parent 91bc629 commit 89edead
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions console/src/user/services/ontology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const useEditPermissions =
);

const useDelete = (): ((props: Ontology.TreeContextMenuProps) => void) => {
const confirm = Ontology.useConfirmDelete({ type: user.ONTOLOGY_TYPE });
const confirm = Ontology.useConfirmDelete({ type: "User" });
return useMutation<void, Error, Ontology.TreeContextMenuProps, Tree.Node[]>({
onMutate: async ({ state: { nodes, setNodes }, selection: { resources } }) => {
if (!(await confirm(resources))) throw errors.CANCELED;
Expand Down Expand Up @@ -67,6 +67,10 @@ const TreeContextMenu: Ontology.TreeContextMenu = (props): ReactElement => {
delete: () => handleDelete(props),
};
const singleResource = resources.length === 1;
const hasRootUser = resources.some((resource) => {
const user = resource.data as user.User;
return user.rootUser;
});
const isNotCurrentUser = resources[0].name !== client.props.username;
const canEditPermissions = Permissions.useSelectCanEditPolicies();
const canEditOrDelete = useSelectHasPermission();
Expand All @@ -75,7 +79,7 @@ const TreeContextMenu: Ontology.TreeContextMenu = (props): ReactElement => {
<PMenu.Menu onChange={handleSelect} level="small" iconSpacing="small">
{singleResource && isNotCurrentUser && (
<>
{canEditPermissions && (
{canEditPermissions && !hasRootUser && (
<PMenu.Item itemKey="permissions" startIcon={<Icon.Access />}>
Edit Permissions
</PMenu.Item>
Expand All @@ -88,7 +92,7 @@ const TreeContextMenu: Ontology.TreeContextMenu = (props): ReactElement => {
<PMenu.Divider />
</>
)}
{canEditOrDelete && (
{canEditOrDelete && !hasRootUser && (
<>
<Menu.DeleteItem />
<PMenu.Divider />
Expand Down

0 comments on commit 89edead

Please sign in to comment.