Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix: some CodeRabbit suggetions

tiran1330cf537ffa707
diff --git a/apps/api/src/events/index.ts b/apps/api/src/events/index.ts
index 67525dfd2..ddfcb0a9b 100644
--- a/apps/api/src/events/index.ts
+++ b/apps/api/src/events/index.ts
@@ -19,14 +19,15 @@ export async function publishEvent(
eventType: string,
data: unknown,
): Promise<void> {
- if (typeof data === "object" && data !== null && "initiatorId" in data) {
+ let enhancedData = null;
+ if (typeof data === "object" && data !== null) {
const store = eventContext.getStore();
- data.initiatorId = store?.initiatorId;
+ enhancedData = { ...data, initiatorId: store?.initiatorId };
}
const payload: EventPayload = {
type: eventType,
- data,
+ data: enhancedData || data,
timestamp: new Date().toISOString(),
};
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 2e06eb867..5f605edf0 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -519,9 +519,21 @@ export function createApp() {
app.get(
"/ws/:projectId",
- upgradeWebSocket((c) => {
+ upgradeWebSocket(async (c) => {
const projectId = c.req.param("projectId");
- const userId = c.req.query("userId") || "anonymous";
+ let userId = "anonymous";
+
+ try {
+ await authenticateApiRequest(c);
+ userId = c.get("userId");
+ } catch (error) {
+ if (error instanceof HTTPException) {
+ throw error;
+ }
+ console.error("API authentication failed:", error);
+ throw new HTTPException(500, { message: "Internal Server Error" });
+ }
+
const windowId = c.req.query("windowId");
const initiatorId = windowId ? `${userId}:${windowId}` : userId;
let conn: ReturnType<typeof addConnection> | null = null;
diff --git a/apps/api/src/label/controllers/assign-label-to-task.ts b/apps/api/src/label/controllers/assign-label-to-task.ts
index 7ef856a9b..04ff4afb1 100644
--- a/apps/api/src/label/controllers/assign-label-to-task.ts
+++ b/apps/api/src/label/controllers/assign-label-to-task.ts
@@ -81,7 +81,9 @@ async function assignLabelToTask(id: string, taskId: string, userId: string) {
await publishEvent("task.label_assigned", {
...updatedLabel,
...task,
- userId: userId,
+ projectId: task.projectId,
+ taskId: task.id,
+ userId,
type: "label_assigned",
});
diff --git a/apps/api/src/label/controllers/create-label.ts b/apps/api/src/label/controllers/create-label.ts
index 924ec2d24..ba48c060f 100644
--- a/apps/api/src/label/controllers/create-label.ts
+++ b/apps/api/src/label/controllers/create-label.ts
@@ -33,7 +33,7 @@ async function createLabel(
const [inserted] = await db
.insert(labelTable)
- .values({ name, color, taskId, workspaceId })
+ .values({ name, color, taskId, workspaceId: task.workspaceId })
.onConflictDoNothing({
target: [labelTable.taskId, labelTable.name],
})
@@ -56,15 +56,14 @@ async function createLabel(
syncLabelToGitea(taskId, name, color).catch((error) => {
console.error("Failed to sync label to Gitea:", error);
});
- }
-
- await publishEvent("task.label_created", {
- ...label,
- ...task,
- userId: userId,
- type: "label_created",
- });
+ await publishEvent("task.label_created", {
+ ...label,
+ ...task,
+ userId: userId,
+ type: "label_created",
+ });
+ }
return label;
}
diff --git a/apps/api/src/label/controllers/delete-label.ts b/apps/api/src/label/controllers/delete-label.ts
index 291fedecb..bbd7c3fbd 100644
--- a/apps/api/src/label/controllers/delete-label.ts
+++ b/apps/api/src/label/controllers/delete-label.ts
@@ -44,6 +44,12 @@ async function deleteLabel(id: string, userId: string) {
.where(eq(labelTable.id, id))
.returning();
+ if (!deletedLabel) {
+ throw new HTTPException(404, {
+ message: "Label not found",
+ });
+ }
+
if (deletedLabel?.taskId) {
removeLabelFromGitHub(deletedLabel.taskId, deletedLabel.name).catch(
(error) => {
@@ -53,7 +59,7 @@ async function deleteLabel(id: string, userId: string) {
}
await publishEvent("task.label_deleted", {
- ...label,
+ ...deletedLabel,
...task,
userId: userId,
type: "label_deleted",
diff --git a/apps/api/src/label/controllers/unassign-label-from-task.ts b/apps/api/src/label/controllers/unassign-label-from-task.ts
index e8b9555c9..e2adf398a 100644
--- a/apps/api/src/label/controllers/unassign-label-from-task.ts
+++ b/apps/api/src/label/controllers/unassign-label-from-task.ts
@@ -60,7 +60,8 @@ async function unassignLabelFromTask(id: string, userId: string) {
await publishEvent("task.label_unassigned", {
...updatedLabel,
...task,
- userId: userId,
+ taskId: label.taskId,
+ userId,
type: "label_unassigned",
});
diff --git a/apps/api/src/task/controllers/move-task.ts b/apps/api/src/task/controllers/move-task.ts
index 0bedd1e81..79696eafd 100644
--- a/apps/api/src/task/controllers/move-task.ts
+++ b/apps/api/src/task/controllers/move-task.ts
@@ -131,12 +131,6 @@ async function moveTask({
destinationStatus,
);
- if (!resolvedColumn) {
- throw new HTTPException(400, {
- message: "Selected status is not valid for the destination project",
- });
- }
-
const movedTask = await db.transaction(async (tx) => {
const [nextTaskNumber, nextPosition] = await Promise.all([
getNextTaskNumber(destinationProjectId, tx),
diff --git a/apps/api/src/task/controllers/update-task-assignee.ts b/apps/api/src/task/controllers/update-task-assignee.ts
index 04e5c7409..6c6470e17 100644
--- a/apps/api/src/task/controllers/update-task-assignee.ts
+++ b/apps/api/src/task/controllers/update-task-assignee.ts
@@ -22,9 +22,15 @@ async function updateTaskAssignee({
message: "Task not found",
});
}
+
+ const nextAssigneeId = userId || null;
+ if (existingTask.userId === nextAssigneeId) {
+ return existingTask;
+ }
+
const [updatedTask] = await db
.update(taskTable)
- .set({ userId: userId || null })
+ .set({ userId: nextAssigneeId || null })
.where(eq(taskTable.id, id))
.returning();
diff --git a/apps/api/src/task/controllers/update-task.ts b/apps/api/src/task/controllers/update-task.ts
index 6ad3bf00a..4e905a43c 100644
--- a/apps/api/src/task/controllers/update-task.ts
+++ b/apps/api/src/task/controllers/update-task.ts
@@ -74,8 +74,10 @@ async function updateTask(
}
await publishEvent("task.updated", {
- ...updatedTask,
taskId: updatedTask.id,
+ projectId: updatedTask.projectId,
+ title: updatedTask.title,
+ status: updatedTask.status,
userId: currentUserId,
});
diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.ts
index fd33a8ddc..503d0bff5 100644
--- a/apps/api/src/task/index.ts
+++ b/apps/api/src/task/index.ts
@@ -24,7 +24,7 @@ import deleteTask from "./controllers/delete-task";
import exportTasks from "./controllers/export-tasks";
import getTask from "./controllers/get-task";
import getTasks from "./controllers/get-tasks";
-import importTasks, { type ImportTask } from "./controllers/import-tasks";
+import importTasks from "./controllers/import-tasks";
import moveTask from "./controllers/move-task";
import updateTask from "./controllers/update-task";
import updateTaskAssignee from "./controllers/update-task-assignee";
@@ -408,7 +408,7 @@ const task = new Hono<{
workspaceAccess.fromProject("projectId"),
async (c) => {
const { projectId } = c.req.valid("param");
- const { tasks }: { tasks: ImportTask[] } = c.req.valid("json");
+ const { tasks } = c.req.valid("json");
const result = await importTasks(projectId, tasks);
diff --git a/apps/api/src/ws/index.ts b/apps/api/src/ws/index.ts
index f39fe6f7e..a0f1792a2 100644
--- a/apps/api/src/ws/index.ts
+++ b/apps/api/src/ws/index.ts
@@ -145,7 +145,6 @@ subscribeToEvent<{
for (const eventName of taskUpdateEvents) {
subscribeToEvent<TaskEvent>(eventName, async (data) => {
- console.log("Broadcasting task update event", eventName);
const { projectId, initiatorId } = data;
const taskId = data.taskId || data.id;
let type: string;
diff --git a/apps/web/src/hooks/mutations/use-sign-out.ts b/apps/web/src/hooks/mutations/use-sign-out.ts
index ffa042db9..cd7ba92c1 100644
--- a/apps/web/src/hooks/mutations/use-sign-out.ts
+++ b/apps/web/src/hooks/mutations/use-sign-out.ts
@@ -30,7 +30,6 @@ function useSignOut(idpLogoutUrl?: string | null) {
url.searchParams.set("id_token_hint", idToken);
}
window.location.href = url.toString();
- console.log("Redirecting to IDP logout URL:", url.toString());
} else {
navigate({ to: "/auth/sign-in" });
}
diff --git a/apps/web/src/hooks/use-project-websocket.ts b/apps/web/src/hooks/use-project-websocket.ts
index bde56cd6b..fc1d26763 100644
--- a/apps/web/src/hooks/use-project-websocket.ts
+++ b/apps/web/src/hooks/use-project-websocket.ts
@@ -3,12 +3,12 @@ import { useQueryClient } from "@tanstack/react-query";
import { useEffect, useRef } from "react";
import { authClient } from "@/lib/auth-client";
-function getWsUrl(projectId: string, userId: string | null | undefined) {
+function getWsUrl(projectId: string) {
const base = (
import.meta.env.VITE_API_URL || "http://localhost:1337"
).replace(/\/+$/, "");
const wsBase = base.replace(/^http/, "ws");
- return `${wsBase}/ws/${projectId}?userId=${userId}&windowId=${windowId}`;
+ return `${wsBase}/ws/${encodeURIComponent(projectId)}?windowId=${encodeURIComponent(windowId)}`;
}
const MAX_RETRIES = 5;
@@ -25,7 +25,7 @@ export function useProjectWebSocket(projectId: string) {
if (!projectId || !session?.user?.id) return;
function connect() {
- const url = getWsUrl(projectId, session?.user?.id);
+ const url = getWsUrl(projectId);
const ws = new WebSocket(url);
wsRef.current = ws;
diff --git a/i18n/es-ES.json b/i18n/es-ES.json
index acbf3ddd6..b78f3b150 100644
--- a/i18n/es-ES.json
+++ b/i18n/es-ES.json
@@ -1062,7 +1062,7 @@
"selectTask": "Seleccionar tarea",
"loadingTask": "Cargando tarea...",
"taskNotFound": "Tarea no encontrada",
- "taskNotFoundDescription": "La tarea que busca no existe o ha sido eliminada."
+ "taskNotFoundDescription": "La tarea que buscas no existe o ha sido eliminada."
},
"detail": {
"subtaskOf": "Subtarea de",