Skip to content

Commit

Permalink
allow admins to kill any run
Browse files Browse the repository at this point in the history
  • Loading branch information
zmc committed Apr 9, 2024
1 parent 33c4f36 commit b98c30a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 46 deletions.
96 changes: 51 additions & 45 deletions src/components/KillButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,26 @@ export default function KillButton(props: KillButtonProps) {
const [open, setOpen] = useState(false);
const mutation: UseMutationResult = props.mutation;
const sessionQuery = useSession();
const loggedUser = sessionQuery.data?.session?.username;
const sessionData = sessionQuery.data?.session;
const username = sessionData?.username;
const isAdmin = sessionData ? sessionData.role == "admin" : false;
console.log("session", sessionData);

if (loggedUser?.toLowerCase() != props.payload["--owner"].toLowerCase()) {
if (username && (
username.toLowerCase() != props.payload["--owner"].toLowerCase()
|| isAdmin
)) {
// logged user and owner of the job should be equal (case insensitive)
return null
}

const toggleDialog = () => {
setOpen(!open);
};


return (
<div>
<div>
<div style={{ display: "flex" }}>
<Button
variant="contained"
Expand All @@ -64,65 +70,65 @@ export default function KillButton(props: KillButtonProps) {
handleClose={toggleDialog}
/>
</div>
{ (mutation.isError) ? <Alert severity="error" message="Unable to kill run" /> : null }
{ (mutation.isSuccess) ? <Alert severity="success" message={`Run killed successfully! \n`} /> : null }
</div>
{(mutation.isError) ? <Alert severity="error" message="Unable to kill run" /> : null}
{(mutation.isSuccess) ? <Alert severity="success" message={`Run killed successfully! \n`} /> : null}
</div>
);
};

function KillButtonDialog({mutation, open, handleClose, payload}: KillButtonDialogProps) {
function KillButtonDialog({ mutation, open, handleClose, payload }: KillButtonDialogProps) {
return (
<div>
<Dialog onClose={handleClose} open={open} scroll="paper" fullWidth={true} maxWidth="sm">
<DialogTitle variant="h6">KILL CONFIRMATION</DialogTitle>
<DialogContent>
{ (mutation.isSuccess && mutation.data ) ?
{(mutation.isSuccess && mutation.data) ?
<div>
<Typography variant="h6" display="block" color="green" gutterBottom>
Successful!
</Typography>
<Paper>
<Typography variant="caption" display="block" gutterBottom>
{mutation.data?.data?.logs}
<Typography variant="h6" display="block" color="green" gutterBottom>
Successful!
</Typography>
</Paper>
</div> :
<Paper>
<Typography variant="caption" display="block" gutterBottom>
{mutation.data?.data?.logs}
</Typography>
</Paper>
</div> :
(mutation.isLoading) ? (
<div style={{display: "flex", alignItems: "center"}}>
<CircularProgress size={20} color="inherit" style={{marginRight: "12px"}} />
<div style={{ display: "flex", alignItems: "center" }}>
<CircularProgress size={20} color="inherit" style={{ marginRight: "12px" }} />
<Typography variant="subtitle1" display="block">
Killing run...
</Typography>
</div>
) :
(mutation.isError) ? (
<div>
<Typography variant="h6" display="block" color="red" gutterBottom>
Failed!
</Typography>
<Paper>
<Typography variant="caption" display="block" gutterBottom>
{mutation.error?.response?.data?.detail}
) :
(mutation.isError) ? (
<div>
<Typography variant="h6" display="block" color="red" gutterBottom>
Failed!
</Typography>
</Paper>
</div>
) :
<div>
<Typography variant="overline" display="block" gutterBottom>
Are you sure you want to kill this run/job?
</Typography>
<Button
variant="contained"
color="error"
size="large"
onClick={() => mutation.mutate(payload)}
>
Yes, I'm sure
</Button>
</div>
<Paper>
<Typography variant="caption" display="block" gutterBottom>
{mutation.error?.response?.data?.detail}
</Typography>
</Paper>
</div>
) :
<div>
<Typography variant="overline" display="block" gutterBottom>
Are you sure you want to kill this run/job?
</Typography>
<Button
variant="contained"
color="error"
size="large"
onClick={() => mutation.mutate(payload)}
>
Yes, I'm sure
</Button>
</div>
}
</DialogContent>
</Dialog>
</div>
)
)
}
5 changes: 4 additions & 1 deletion src/lib/teuthologyAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
export type Session = {
session: {
id: int,
username: string
role: string,
state: string,
username: string,
access_token: string,
}
}

Expand Down

0 comments on commit b98c30a

Please sign in to comment.