Skip to content

Commit

Permalink
KillButton: Add "Kill as Admin" btn
Browse files Browse the repository at this point in the history
If the run belongs to the logged-in user, then it'll
show "Kill" button. If not, then  "Kill As Admin" btn.
For now, pulpito-ng does not verify if user has admin
privileges. That check happens on t-api after the request is sent.

This commit also refreshes the mutation obj for kill-button,
upon button click. This fixes the issue of retrying to kill runs
by clicking the button again.

Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Apr 24, 2024
1 parent 33c4f36 commit 1b7690c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
29 changes: 15 additions & 14 deletions src/components/KillButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Alert from "../Alert";

type KillButtonProps = {
mutation: UseMutationResult;
text: string;
payload: KillRunPayload;
disabled?: boolean;
};
Expand All @@ -34,14 +33,16 @@ export default function KillButton(props: KillButtonProps) {
const sessionQuery = useSession();
const loggedUser = sessionQuery.data?.session?.username;

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

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

const refreshAndtoggle = () => {
toggleDialog();
mutation.reset();
}


return (
Expand All @@ -51,11 +52,11 @@ export default function KillButton(props: KillButtonProps) {
variant="contained"
color="error"
size="large"
onClick={toggleDialog}
onClick={refreshAndtoggle}
disabled={(props.disabled || mutation.isLoading)}
sx={{ marginBottom: "12px" }}
>
{props.text}
{(isOwner) ? "Kill" : "Kill As Admin"}
</Button>
<KillButtonDialog
mutation={mutation}
Expand All @@ -78,14 +79,14 @@ function KillButtonDialog({mutation, open, handleClose, payload}: KillButtonDial
<DialogContent>
{ (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>
<Paper>
<Typography variant="caption" display="block" gutterBottom>
{mutation.data?.data?.logs}
</Typography>
</Paper>
</div> :
(mutation.isLoading) ? (
<div style={{display: "flex", alignItems: "center"}}>
Expand Down
1 change: 0 additions & 1 deletion src/pages/Run/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export default function Run() {
</div>
<KillButton
mutation={killMutation}
text="Kill run"
payload={killPayload}
disabled={(data?.status.includes("finished"))}
/>
Expand Down

0 comments on commit 1b7690c

Please sign in to comment.