diff --git a/src/components/KillButton/index.tsx b/src/components/KillButton/index.tsx
index 5f32eec..9ca5526 100644
--- a/src/components/KillButton/index.tsx
+++ b/src/components/KillButton/index.tsx
@@ -3,20 +3,28 @@ import Button from "@mui/material/Button";
import Box from "@mui/material/Box";
import { CircularProgress } from "@mui/material";
-import { KillRun } from "../../lib/teuthologyAPI.d";
+import { KillRunPayload } from "../../lib/teuthologyAPI.d";
+import { useSession } from "../../lib/teuthologyAPI";
import Alert from "../Alert";
type KillButtonProps = {
mutation: UseMutationResult;
text: string;
- payload: KillRun;
+ payload: KillRunPayload;
+ disabled?: boolean;
};
export default function KillButton(props: KillButtonProps) {
const mutation: UseMutationResult = props.mutation;
-
+ const sessionQuery = useSession();
+ const loggedUser = sessionQuery.data?.session.username;
+
+ if (loggedUser?.toLowerCase() != props.payload["--user"].toLowerCase()) {
+ // logged user and owner of the job should be equal (case insensitive)
+ return null
+ }
return (
@@ -26,7 +34,7 @@ export default function KillButton(props: KillButtonProps) {
color="error"
size="large"
onClick={() => mutation.mutate(props.payload)}
- disabled={(mutation.isLoading)}
+ disabled={(props.disabled || mutation.isLoading)}
>
{props.text}
diff --git a/src/lib/paddles.d.ts b/src/lib/paddles.d.ts
index f180600..0bc7bca 100644
--- a/src/lib/paddles.d.ts
+++ b/src/lib/paddles.d.ts
@@ -24,6 +24,7 @@ export type Job = {
suite: string;
branch: string;
scheduled: string;
+ owner: string;
};
export type RunResults = {
@@ -39,6 +40,7 @@ export type Run = {
results: RunResults;
user: string;
machine_type: string;
+ status: string;
};
export type Node = {
diff --git a/src/lib/teuthologyAPI.d.ts b/src/lib/teuthologyAPI.d.ts
index 85fd2b8..3a8aa35 100644
--- a/src/lib/teuthologyAPI.d.ts
+++ b/src/lib/teuthologyAPI.d.ts
@@ -1,5 +1,12 @@
-export type KillRun = {
+export type Session = {
+ session: {
+ id: int,
+ username: string
+ }
+}
+
+export type KillRunPayload = {
"--run": string,
"--owner": string,
"--machine-type": string,
diff --git a/src/lib/teuthologyAPI.ts b/src/lib/teuthologyAPI.ts
index 45a3a13..ee85ddc 100644
--- a/src/lib/teuthologyAPI.ts
+++ b/src/lib/teuthologyAPI.ts
@@ -2,6 +2,7 @@ import axios from "axios";
import { useQuery, useMutation } from "@tanstack/react-query";
import type { UseQueryResult, UseMutationResult } from "@tanstack/react-query";
import { Cookies } from "react-cookie";
+import { Session } from "./teuthologyAPI.d"
const TEUTHOLOGY_API_SERVER =
import.meta.env.VITE_TEUTHOLOGY_API || "";
@@ -25,9 +26,9 @@ function doLogout() {
window.location.href = url;
}
-function useSession(): UseQueryResult {
+function useSession(): UseQueryResult {
const url = getURL("/");
- const query = useQuery({
+ const query = useQuery({
queryKey: ['ping-api', { url }],
queryFn: () => (
axios.get(url, {
diff --git a/src/pages/Run/index.tsx b/src/pages/Run/index.tsx
index cff668b..b1c0316 100644
--- a/src/pages/Run/index.tsx
+++ b/src/pages/Run/index.tsx
@@ -15,7 +15,7 @@ import { useRunKill } from "../../lib/teuthologyAPI";
import JobList from "../../components/JobList";
import Link from "../../components/Link";
import KillButton from "../../components/KillButton";
-import { KillRun } from '../../lib/teuthologyAPI.d';
+import { KillRunPayload } from '../../lib/teuthologyAPI.d';
const PREFIX = "index";
@@ -68,9 +68,10 @@ export default function Run() {
const date = query.data?.scheduled
? format(new Date(query.data.scheduled), "yyyy-MM-dd")
: null;
- const killPayload: KillRun = {
+ const run_owner = data?.jobs[0].owner || "";
+ const killPayload: KillRunPayload = {
"--run": data?.name || "",
- "--owner": data?.user || "",
+ "--owner": run_owner,
"--machine-type": data?.machine_type || "",
"--user": data?.user || "",
}
@@ -94,7 +95,12 @@ export default function Run() {
date
-
+