⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix: resolve comment markdown conflicts and review feedback
Tin32bae04be236
diff --cc apps/api/src/activity/index.tsindex 16e63c599,109c5f119..4221dcaed--- a/apps/api/src/activity/index.ts+++ b/apps/api/src/activity/index.ts@@@ -1,9 -1,10 +1,12 @@@- import { Hono } from "hono";+import { HTTPException } from "hono/http-exception";- import { describeRoute, resolver, validator } from "hono-openapi";- import * as v from "valibot";import { subscribeToEvent } from "../events";- import { activitySchema } from "../schemas";+ import {+ apiRouter,+ createRoute,+ errorResponse,+ jsonResponse,++ z,+ } from "../openapi";import { requireWorkspacePermission } from "../utils/require-workspace-permission";import { workspaceAccess } from "../utils/workspace-access-middleware";import createActivity from "./controllers/create-activity";@@@ -11,181 -12,159 +14,174 @@@ import createComment from "./controllerimport deleteComment from "./controllers/delete-comment";import getActivities from "./controllers/get-activities";import updateComment from "./controllers/update-comment";+ import { activityListSchema, activitySchema } from "./response";+ import {+ createActivityBody,+ createCommentBody,+ deleteCommentBody,+ taskIdParam,+ updateCommentBody,+ } from "./schema";- const activityCommentContentSchema = v.pipe(v.string(), v.maxLength(10_000));- const activityErrorSchema = v.object({ message: v.string() });+ const getActivitiesRoute = createRoute({+ method: "get",+ operationId: "getActivities",+ path: "/{taskId}",+ tags: ["Activity"],+ summary: "Get task activity",+ description:+ "Get a task's full activity feed, newest first: comments alongside system events such as status and assignee changes.",+ middleware: [workspaceAccess.fromTaskId()] as const,+ request: { params: taskIdParam },+ responses: {+ 200: jsonResponse("List of activities for the task", activityListSchema),+ 400: errorResponse(+ "Unknown task, or its workspace could not be determined",+ ),+ 403: errorResponse("No access to the task's workspace"),+ },+ });- const activity = new Hono<{- Variables: {- userId: string;- };- }>()- .get(- "/:taskId",- describeRoute({- operationId: "getActivities",- tags: ["Activity"],- description: "Get all activities for a specific task",- responses: {- 200: {- description: "List of activities for the task",- content: {- "application/json": { schema: resolver(v.array(activitySchema)) },- },- },- },- }),- validator("param", v.object({ taskId: v.string() })),+ const createActivityRoute = createRoute({+ method: "post",+ operationId: "createActivity",+ path: "/create",+ tags: ["Activity"],+ summary: "Create activity",+ description:+ "Record a system-generated event on a task. Most events are written by the server itself; this exists for importers and integrations.",+ middleware: [workspaceAccess.fromTaskId(),- async (c) => {- const { taskId } = c.req.valid("param");- const activities = await getActivities(taskId);- return c.json(activities);+ requireWorkspacePermission({ task: ["update"] }),+ ] as const,+ request: {+ body: {+ required: true,+ content: { "application/json": { schema: createActivityBody } },},- )- .post(- "/create",- describeRoute({- operationId: "createActivity",- tags: ["Activity"],- description: "Create a new activity (system-generated event)",- responses: {- 200: {- description: "Activity created successfully",- content: {- "application/json": { schema: resolver(activitySchema) },- },- },- 400: {- description: "Comment activities must use the comment endpoint",- content: {- "application/json": { schema: resolver(activityErrorSchema) },- },- },+ },+ responses: {+ 200: jsonResponse("The created activity", activitySchema),- 400: errorResponse("Invalid body, or unknown task"),++ 400: {++ description:++ "Invalid body, unknown task, or comment activity submitted through the generic endpoint",++ content: {++ "text/plain": { schema: z.string() },++ "application/json": { schema: z.object({ message: z.string() }) },+ },- }),- validator(- "json",- v.object({- taskId: v.string(),- userId: v.string(),- message: v.nullable(v.string()),- type: v.string(),- eventData: v.optional(v.nullable(v.record(v.string(), v.unknown()))),- }),++ },+ 403: errorResponse(+ "No workspace access, or missing task:update permission",),+ },+ });++ const createCommentRoute = createRoute({+ method: "post",+ operationId: "createComment",+ path: "/comment",+ tags: ["Activity"],+ summary: "Create comment",+ description:+ "Add a comment to a task. Equivalent to POST /comment/{taskId}, kept for the activity-feed client.",+ middleware: [workspaceAccess.fromTaskId(),requireWorkspacePermission({ task: ["update"] }),- async (c) => {- const { taskId, userId, message, type, eventData } = c.req.valid("json");- if (type === "comment") {- throw new HTTPException(400, {- res: c.json(- { message: "Use the comment endpoint to create comments" },- 400,- ),- });- }- const activity = await createActivity(- taskId,- type,- userId,- message,- eventData,- );- return c.json(activity);+ ] as const,+ request: {+ body: {+ required: true,+ content: { "application/json": { schema: createCommentBody } },},- )- .post(- "/comment",- describeRoute({- operationId: "createComment",- tags: ["Activity"],- description: "Create a new comment on a task",- responses: {- 200: {- description: "Comment created successfully",- content: {- "application/json": { schema: resolver(activitySchema) },- },- },- },- }),- validator(- "json",- v.object({- taskId: v.string(),- comment: activityCommentContentSchema,- }),+ },+ responses: {+ 200: jsonResponse("The created comment", activitySchema),+ 400: errorResponse("Invalid body, or unknown task"),+ 403: errorResponse(+ "No workspace access, or missing task:update permission",),- workspaceAccess.fromTaskId(),- requireWorkspacePermission({ task: ["update"] }),- async (c) => {- const { taskId, comment } = c.req.valid("json");- const userId = c.get("userId");- const newComment = await createComment(taskId, userId, comment);+ },+ });- return c.json(newComment);+ const updateCommentRoute = createRoute({+ method: "put",+ operationId: "updateComment",+ path: "/comment",+ tags: ["Activity"],+ summary: "Update comment",+ description: "Edit a comment. Only the comment's author may do this.",+ middleware: [workspaceAccess.fromActivity("activityId")] as const,+ request: {+ body: {+ required: true,+ content: { "application/json": { schema: updateCommentBody } },},- )- .put(- "/comment",- describeRoute({- operationId: "updateComment",- tags: ["Activity"],- description: "Update an existing comment",- responses: {- 200: {- description: "Comment updated successfully",- content: {- "application/json": { schema: resolver(activitySchema) },- },- },- },- }),- validator(- "json",- v.object({- activityId: v.string(),- comment: activityCommentContentSchema,- }),- ),- workspaceAccess.fromActivity("activityId"),- async (c) => {- const { activityId, comment } = c.req.valid("json");- const userId = c.get("userId");- const updatedComment = await updateComment(userId, activityId, comment);- return c.json(updatedComment);+ },+ responses: {+ 200: jsonResponse("The updated comment", activitySchema),+ 400: errorResponse("Invalid body, or unknown activity"),+ 403: errorResponse("Not the author, or no access to the workspace"),+ 404: errorResponse("Comment not found"),+ },+ });++ const deleteCommentRoute = createRoute({+ method: "delete",+ operationId: "deleteComment",+ path: "/comment",+ tags: ["Activity"],+ summary: "Delete comment",+ description: "Delete a comment. Only the comment's author may do this.",+ middleware: [workspaceAccess.fromActivity("activityId")] as const,+ request: {+ body: {+ required: true,+ content: { "application/json": { schema: deleteCommentBody } },},+ },+ responses: {+ 200: jsonResponse("The deleted comment", activitySchema),+ 400: errorResponse("Invalid body, or unknown activity"),+ 403: errorResponse("Not the author, or no access to the workspace"),+ 404: errorResponse("Comment not found"),+ },+ });++ const activity = apiRouter()+ .openapi(getActivitiesRoute, async (c) =>+ c.json(await getActivities(c.req.valid("param").taskId), 200),)- .delete(- "/comment",- describeRoute({- operationId: "deleteComment",- tags: ["Activity"],- description: "Delete a comment",- responses: {- 200: {- description: "Comment deleted successfully",- content: {- "application/json": { schema: resolver(activitySchema) },- },- },- },- }),- validator(- "json",- v.object({- activityId: v.string(),- }),+ .openapi(createActivityRoute, async (c) => {+ const { taskId, message, type, eventData } = c.req.valid("json");++ if (type === "comment") {++ throw new HTTPException(400, {++ res: c.json(++ { message: "Use the comment endpoint to create comments" },++ 400,++ ),++ });++ }+ return c.json(+ await createActivity(taskId, type, c.get("userId"), message, eventData),+ 200,+ );+ })+ .openapi(createCommentRoute, async (c) => {+ const { taskId, comment } = c.req.valid("json");+ return c.json(await createComment(taskId, c.get("userId"), comment), 200);+ })+ .openapi(updateCommentRoute, async (c) => {+ const { activityId, comment } = c.req.valid("json");+ return c.json(+ await updateComment(c.get("userId"), activityId, comment),+ 200,+ );+ })+ .openapi(deleteCommentRoute, async (c) =>+ c.json(+ await deleteComment(c.get("userId"), c.req.valid("json").activityId),+ 200,),- workspaceAccess.fromActivity("activityId"),- async (c) => {- const { activityId } = c.req.valid("json");- const userId = c.get("userId");- const deletedComment = await deleteComment(userId, activityId);- return c.json(deletedComment);- },);subscribeToEvent<{diff --cc apps/api/src/activity/schema.tsindex 000000000,7b7946ef9..ef06d4145mode 000000,100644..100644--- a/apps/api/src/activity/schema.ts+++ b/apps/api/src/activity/schema.ts@@@ -1,0 -1,29 +1,29 @@@+ import { z } from "../openapi";++ export const taskIdParam = z.object({ taskId: z.string() });++ export const createActivityBody = z.object({+ taskId: z.string(),+ message: z.string().nullable().openapi({+ description:+ "Free-text body. Null for events whose meaning is in eventData.",+ }),+ type: z.string().openapi({+ description: "The event kind, e.g. status_changed or assignee_changed.",+ }),+ eventData: z.record(z.string(), z.unknown()).nullable().optional().openapi({+ description: "Type-specific payload stored alongside the event.",+ }),+ });++ export const createCommentBody = z.object({+ taskId: z.string(),- comment: z.string(),++ comment: z.string().max(10_000),+ });++ export const updateCommentBody = z.object({+ activityId: z.string(),- comment: z.string(),++ comment: z.string().max(10_000),+ });++ export const deleteCommentBody = z.object({ activityId: z.string() });diff --cc apps/docs/openapi.jsonindex f070001a4,f4f27f221..1fe031360--- a/apps/docs/openapi.json+++ b/apps/docs/openapi.json@@@ -8905,108 -8264,51 +8264,64 @@@}}},- "summary": "Create Slack Integration"- },- "patch": {- "operationId": "updateSlackIntegration",- "tags": [- "Slack"- ],- "description": "Update Slack integration settings","responses": {"200": {- "description": "Slack integration updated successfully",+ "description": "The created activity",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/Activity"+ }+ }+ }+ },+ "400": {- "description": "Invalid body, or unknown task",++ "description": "Invalid body, unknown task, or comment activity submitted through the generic endpoint","content": {+ "text/plain": {+ "schema": {+ "type": "string"+ }++ },+ "application/json": {+ "schema": {+ "type": "object",+ "properties": {- "id": {- "type": "string"- },- "projectId": {- "type": "string"- },- "channelName": {- "type": "string",- "nullable": true- },- "webhookConfigured": {- "type": "boolean"- },- "maskedWebhookUrl": {++ "message": {+ "type": "string"- },- "events": {- "type": "object",- "properties": {- "taskCreated": {- "type": "boolean"- },- "taskStatusChanged": {- "type": "boolean"- },- "taskPriorityChanged": {- "type": "boolean"- },- "taskTitleChanged": {- "type": "boolean"- },- "taskDescriptionChanged": {- "type": "boolean"- },- "taskCommentCreated": {- "type": "boolean"- }- },- "required": [- "taskCreated",- "taskStatusChanged",- "taskPriorityChanged",- "taskTitleChanged",- "taskDescriptionChanged",- "taskCommentCreated"- ]- },- "isActive": {- "type": "boolean",- "nullable": true- },- "createdAt": {- "type": "string",- "format": "date-time"- },- "updatedAt": {- "type": "string",- "format": "date-time"+ }+ },+ "required": [- "id",- "projectId",- "channelName",- "webhookConfigured",- "maskedWebhookUrl",- "events",- "isActive",- "createdAt",- "updatedAt"++ "message"+ ]+ }}}+ },+ "401": {+ "description": "Missing or invalid credentials"+ },+ "403": {+ "description": "No workspace access, or missing task:update permission",+ "content": {+ "text/plain": {+ "schema": {+ "type": "string"+ }+ }+ }}- },- "parameters": [- {- "in": "path",- "name": "projectId",- "schema": {- "type": "string"- },- "required": true- }+ }+ }+ },+ "/activity/comment": {+ "post": {+ "operationId": "createComment",+ "tags": [+ "Activity"],+ "summary": "Create comment",+ "description": "Add a comment to a task. Equivalent to POST /comment/{taskId}, kept for the activity-feed client.","requestBody": {"required": true,"content": {@@@ -9014,55 -8316,89 +8329,91 @@@"schema": {"type": "object","properties": {- "webhookUrl": {+ "taskId": {"type": "string"},- "channelName": {+ "comment": {- "type": "string"+ "type": "string",- "nullable": true- },- "isActive": {- "type": "boolean"- },- "events": {- "type": "object",- "properties": {- "taskCreated": {- "type": "boolean"- },- "taskStatusChanged": {- "type": "boolean"- },- "taskPriorityChanged": {- "type": "boolean"- },- "taskTitleChanged": {- "type": "boolean"- },- "taskDescriptionChanged": {- "type": "boolean"- },- "taskCommentCreated": {- "type": "boolean"- }- }++ "maxLength": 10000}- }+ },+ "required": [+ "taskId",+ "comment"+ ]}}}},- "summary": "Update Slack Integration"+ "responses": {+ "200": {+ "description": "The created comment",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/Activity"+ }+ }+ }+ },+ "400": {+ "description": "Invalid body, or unknown task",+ "content": {+ "text/plain": {+ "schema": {+ "type": "string"+ }+ }+ }+ },+ "401": {+ "description": "Missing or invalid credentials"+ },+ "403": {+ "description": "No workspace access, or missing task:update permission",+ "content": {+ "text/plain": {+ "schema": {+ "type": "string"+ }+ }+ }+ }+ }},- "delete": {- "operationId": "deleteSlackIntegration",+ "put": {+ "operationId": "updateComment","tags": [- "Slack"+ "Activity"],- "description": "Delete Slack integration for a project",+ "summary": "Update comment",+ "description": "Edit a comment. Only the comment's author may do this.",+ "requestBody": {+ "required": true,+ "content": {+ "application/json": {+ "schema": {+ "type": "object",+ "properties": {+ "activityId": {+ "type": "string"+ },+ "comment": {- "type": "string"++ "type": "string",++ "maxLength": 10000+ }+ },+ "required": [+ "activityId",+ "comment"+ ]+ }+ }+ }+ },"responses": {"200": {- "description": "Slack integration deleted successfully",+ "description": "The updated comment","content": {"application/json": {"schema": {diff --cc apps/web/src/components/activity/comment-editor.tsxindex b1c467c40,e7ede83f2..1e4c72b9a--- a/apps/web/src/components/activity/comment-editor.tsx+++ b/apps/web/src/components/activity/comment-editor.tsx@@@ -71,8 -70,6 +70,7 @@@ importnormalizeUrl,} from "@/lib/editor-url-utils";import { isInCodeBlockLanguagePicker } from "@/lib/is-in-codeblock-language-picker";+import { normalizeCommentMarkdown } from "@/lib/normalize-comment-markdown";- import { getSharedShikiHighlighter } from "@/lib/shiki-highlighter";import { toast } from "@/lib/toast";import { uploadTaskImage } from "@/lib/upload-task-image";diff --cc tests/api-integration/comment.test.tsindex 659dc7349,9955410fb..928f51fa0--- a/tests/api-integration/comment.test.ts+++ b/tests/api-integration/comment.test.ts@@@ -97,38 -95,7 +97,128 @@@ describe("API integration: task commentexpect(legacyComments).toHaveLength(0);});- it("rejects creating comments over the activity API length limit", async () => {++ it.each([++ { length: 10_000, status: 200 },++ { length: 10_001, status: 400 },++ ])(++ "returns $status when creating a $length-character comment",++ async ({ length, status }) => {++ const member = await createWorkspaceMember();++ const { project, columns } = await createProjectFixture({++ workspaceId: member.workspace.id,++ });++ const [task] = await db++ .insert(schema.taskTable)++ .values({++ projectId: project.id,++ title: "Comment length limit",++ status: "to-do",++ columnId: columns.todo.id,++ priority: "medium",++ number: 1,++ position: 1,++ })++ .returning();++++ mockAuthenticatedSession(member.user);++ const { app } = createApp();++++ const comment = "x".repeat(length);++ const response = await app.request("/api/activity/comment", {++ method: "POST",++ headers: { "content-type": "application/json" },++ body: JSON.stringify({ taskId: task.id, comment }),++ });++++ expect(response.status).toBe(status);++ },++ );++++ it.each([++ { length: 10_000, status: 200 },++ { length: 10_001, status: 400 },++ ])(++ "returns $status when updating a $length-character comment",++ async ({ length, status }) => {++ const member = await createWorkspaceMember();++ const { project, columns } = await createProjectFixture({++ workspaceId: member.workspace.id,++ });++ const [task] = await db++ .insert(schema.taskTable)++ .values({++ projectId: project.id,++ title: "Comment length limit",++ status: "to-do",++ columnId: columns.todo.id,++ priority: "medium",++ number: 1,++ position: 1,++ })++ .returning();++ mockAuthenticatedSession(member.user);++ const { app } = createApp();++ const createResponse = await app.request("/api/activity/comment", {++ method: "POST",++ headers: { "content-type": "application/json" },++ body: JSON.stringify({ taskId: task.id, comment: "Short comment" }),++ });++ expect(createResponse.status).toBe(200);++ const createdComment = (await createResponse.json()) as { id: string };++ const comment = "x".repeat(length);++++ const response = await app.request("/api/activity/comment", {++ method: "PUT",++ headers: { "content-type": "application/json" },++ body: JSON.stringify({++ activityId: createdComment.id,++ comment,++ }),++ });++++ expect(response.status).toBe(status);++ },++ );++++ it("rejects comments through the generic activity endpoint", async () => {+ const member = await createWorkspaceMember();+ const { project, columns } = await createProjectFixture({+ workspaceId: member.workspace.id,+ });+ const [task] = await db+ .insert(schema.taskTable)+ .values({+ projectId: project.id,- title: "Comment length limit",++ title: "Generic comment activity",+ status: "to-do",+ columnId: columns.todo.id,+ priority: "medium",+ number: 1,+ position: 1,+ })+ .returning();-+ mockAuthenticatedSession(member.user);+ const { app } = createApp();+- const overlongComment = "x".repeat(10_001);- const response = await app.request("/api/activity/comment", {++ const response = await app.request("/api/activity/create", {+ method: "POST",+ headers: { "content-type": "application/json" },- body: JSON.stringify({ taskId: task.id, comment: overlongComment }),++ body: JSON.stringify({++ taskId: task.id,++ userId: member.user.id,++ message: "Comment through generic endpoint",++ type: "comment",++ }),+ });++ expect(response.status).toBe(400);++ expect(response.headers.get("content-type")).toContain("application/json");++ expect(await response.json()).toEqual({++ message: "Use the comment endpoint to create comments",++ });+ });+- it("rejects updating comments over the activity API length limit", async () => {+ it("records an external author when both name and source are given", async () => {const member = await createWorkspaceMember();const { project, columns } = await createProjectFixture({workspaceId: member.workspace.id,