Skip to content

Commit

Permalink
KillButton: don't show btn if user logged out or run's finished
Browse files Browse the repository at this point in the history
Fixes: #51 (review)

Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Sep 25, 2024
1 parent 5c733ec commit e702359
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/KillButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ export default function KillButton(props: KillButtonProps) {
const isUserAdmin = sessionQuery.data?.session?.isUserAdmin;
const owner = props.payload["--owner"].toLowerCase()
const isOwner = (loggedUser?.toLowerCase() == owner) || (`scheduled_${loggedUser?.toLowerCase()}@teuthology` == owner)
const isButtonDisabled = ((props.disabled) || (!isOwner && !isUserAdmin))
const isButtonDisabled = (!isOwner && !isUserAdmin)

const getHelperMessage = () => {
if (isButtonDisabled) {
if (!isOwner && !isUserAdmin) return "You don't have admin privileges to kill runs owned by another user. ";
return "All jobs in the run have already finished";
return `User (${loggedUser}) does not have admin privileges to kill runs owned by another user (${owner}). `;
} else {
if (!isOwner && isUserAdmin) return "Use admin privileges to kill another user's run.";
if (!isOwner && isUserAdmin) return `Use admin privileges to kill run owned by '${owner}'. `;
return "Terminate all jobs in this run";
}
}
Expand All @@ -57,6 +56,11 @@ export default function KillButton(props: KillButtonProps) {
toggleDialog();
mutation.reset();
}

if (props.disabled || !(sessionQuery.data?.session?.username)) {
// run finished or user logged out
return null;
}


return (
Expand Down

0 comments on commit e702359

Please sign in to comment.