Skip to content

Commit

Permalink
KillButton: disable when user is not admin
Browse files Browse the repository at this point in the history
Read "isUserAdmin" from useSession and
disable "Kill as Admin" button if isUserAdmin is false

Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed May 10, 2024
1 parent a025f24 commit 2d50003
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/components/KillButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DialogContent from '@mui/material/DialogContent';
import Dialog from '@mui/material/Dialog';
import Paper from "@mui/material/Paper";
import Typography from "@mui/material/Typography";
import Tooltip from '@mui/material/Tooltip';

import { KillRunPayload } from "../../lib/teuthologyAPI.d";
import { useSession } from "../../lib/teuthologyAPI";
Expand All @@ -32,7 +33,7 @@ export default function KillButton(props: KillButtonProps) {
const mutation: UseMutationResult = props.mutation;
const sessionQuery = useSession();
const loggedUser = sessionQuery.data?.session?.username;

const isUserAdmin = sessionQuery.data?.session?.isUserAdmin;
const owner = props.payload["--owner"].toLowerCase()
const isOwner = (loggedUser?.toLowerCase() == owner) || (`scheduled_${loggedUser?.toLowerCase()}@teuthology` == owner)

Expand All @@ -49,16 +50,21 @@ export default function KillButton(props: KillButtonProps) {
return (
<div>
<div style={{ display: "flex" }}>
<Tooltip arrow title={(isUserAdmin ? "User has admin privileges": "User does not have admin privileges")}>
<span>
<Button
variant="contained"
color="error"
size="large"
onClick={refreshAndtoggle}
disabled={(props.disabled || mutation.isLoading)}
disabled={((props.disabled || mutation.isLoading) ||
(!isOwner && !isUserAdmin))}
sx={{ marginBottom: "12px" }}
>
{(isOwner) ? "Kill" : "Kill As Admin"}
</Button>
</span>
</Tooltip>
<KillButtonDialog
mutation={mutation}
payload={props.payload}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/teuthologyAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
export type Session = {
session: {
id: int,
username: string
username: string,
isUserAdmin: boolean,
}
}

Expand Down

0 comments on commit 2d50003

Please sign in to comment.