From c0b50c75fd816eb060500f52e44a7d3fda8a98bd Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 20 Apr 2024 10:57:08 +0200 Subject: [PATCH] Can set VM rights for API tokens --- .../src/widgets/tokens/TokenRightsEditor.tsx | 250 +++++++++++++++++- 1 file changed, 240 insertions(+), 10 deletions(-) diff --git a/virtweb_frontend/src/widgets/tokens/TokenRightsEditor.tsx b/virtweb_frontend/src/widgets/tokens/TokenRightsEditor.tsx index b568d76..8031421 100644 --- a/virtweb_frontend/src/widgets/tokens/TokenRightsEditor.tsx +++ b/virtweb_frontend/src/widgets/tokens/TokenRightsEditor.tsx @@ -2,6 +2,11 @@ import { Checkbox, FormControlLabel, Paper, + Table, + TableBody, + TableCell, + TableHead, + TableRow, Tooltip, Typography, } from "@mui/material"; @@ -22,6 +27,215 @@ export function TokenRightsEditor(p: { }): React.ReactElement { return ( <> + {/* Virtual machines */} + + + + + + + + + + + VM name + Get definition + Update + Delete + Get XML definition + Get autostart + Set autostart + + + + {/* All VM operations */} + + + All + + + + + + + + + + {/* Per VM operations */} + {p.vms.map((v, n) => ( + + {v.name} + + + + + + + + ))} + +
+
+ + + + + + VM name + Get state + Start + Shutdown + Kill + Reset + Suspend + Resume + Screenshot + VNC token + + + + {/* All VM operations */} + + + All + + + + + + + + + + + + + {/* Per VM operations */} + {p.vms.map((v, n) => ( + + {v.name} + + + + + + + + + + + ))} + +
+
{/* ISO files */} ): React.ReactElement { return ( - + {p.label} {p.children} ); } -function RouteRight(p: { +interface RightOpts { right: TokenRight; label?: string; editable: boolean; token: APIToken; onChange?: () => void; parent?: TokenRight; -}): React.ReactElement { - const activated = - p.token.rights.find( - (r) => r.verb === p.right.verb && r.path === p.right.path - ) !== undefined; +} + +function CellRight(p: RightOpts): React.ReactElement { + return ( + + + + ); +} + +function RouteRight(p: RightOpts): React.ReactElement { + const rightIndex = p.token.rights.findIndex( + (r) => r.verb === p.right.verb && r.path === p.right.path + ); + const activated = rightIndex !== -1; + + const parentActivated = + !!p.parent && + p.token.rights.findIndex( + (r) => r.verb === p.parent?.verb && r.path === p.parent?.path + ) !== -1; const toggle = (a: boolean) => { if (a) { p.token.rights.push(p.right); } else { - p.token.rights.splice(p.token.rights.indexOf(p.right), 1); + p.token.rights.splice(rightIndex, 1); } p.onChange?.(); }; @@ -138,8 +368,8 @@ function RouteRight(p: { toggle(a)} /> }