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(integrations): require task update permission for imports

Tinefb87ccbae4f
diff --git a/apps/api/src/gitea-integration/index.ts b/apps/api/src/gitea-integration/index.ts
index 5ff687705..287206172 100644
--- a/apps/api/src/gitea-integration/index.ts
+++ b/apps/api/src/gitea-integration/index.ts
@@ -204,7 +204,7 @@ const importIssuesRoute = createRoute({
"Import the linked repository's issues as tasks. Issues that already have a task are refreshed rather than duplicated.",
middleware: [
scopeToProjectFromBody,
- requireWorkspacePermission({ task: ["create"] }),
+ requireWorkspacePermission({ task: ["create", "update"] }),
] as const,
request: {
body: {
@@ -216,7 +216,7 @@ const importIssuesRoute = createRoute({
200: jsonResponse("Import summary", giteaImportResultSchema),
400: errorResponse("projectId is required"),
403: errorResponse(
- "No workspace access, or missing task:create permission",
+ "No workspace access, or missing task:create or task:update permission",
),
404: errorResponse("Project not found"),
},
diff --git a/apps/api/src/github-integration/index.ts b/apps/api/src/github-integration/index.ts
index b6cb39116..458765342 100644
--- a/apps/api/src/github-integration/index.ts
+++ b/apps/api/src/github-integration/index.ts
@@ -229,7 +229,7 @@ const importIssuesRoute = createRoute({
"Import open issues and link open pull requests in bounded steps. Existing tasks are updated. Continue 202 responses with the returned runId until 200; the same runId safely retries completion. Progress is saved after each page. New calls without runId resume an unfinished import or start a new one after completion.",
middleware: [
scopeToProjectFromBody,
- requireWorkspacePermission({ task: ["create"] }),
+ requireWorkspacePermission({ task: ["create", "update"] }),
] as const,
request: {
body: {
@@ -252,7 +252,7 @@ const importIssuesRoute = createRoute({
),
400: errorResponse("projectId is required"),
403: errorResponse(
- "No workspace access, or missing task:create permission",
+ "No workspace access, or missing task:create or task:update permission",
),
404: errorResponse("Project not found"),
},
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index b263bb917..37a6c9541 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -13084,7 +13084,7 @@
"description": "Missing or invalid credentials"
},
"403": {
- "description": "No workspace access, or missing task:create permission",
+ "description": "No workspace access, or missing task:create or task:update permission",
"content": {
"text/plain": {
"schema": {
@@ -13647,7 +13647,7 @@
"description": "Missing or invalid credentials"
},
"403": {
- "description": "No workspace access, or missing task:create permission",
+ "description": "No workspace access, or missing task:create or task:update permission",
"content": {
"text/plain": {
"schema": {
diff --git a/tests/api-integration/integration-import-permissions.test.ts b/tests/api-integration/integration-import-permissions.test.ts
new file mode 100644
index 000000000..e3b540c33
--- /dev/null
+++ b/tests/api-integration/integration-import-permissions.test.ts
@@ -0,0 +1,85 @@
+import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
+import db, { schema } from "../../apps/api/src/database";
+import { createApp } from "../../apps/api/src/index";
+import { mockAuthenticatedSession } from "./helpers/auth";
+import { resetTestDatabase } from "./helpers/database";
+import {
+ createProjectFixture,
+ createWorkspaceMember,
+} from "./helpers/fixtures";
+
+const provider = vi.hoisted(() => ({
+ listIssues: vi.fn(async () => []),
+ listPulls: vi.fn(async () => []),
+}));
+vi.mock(
+ "../../apps/api/src/plugins/gitea/utils/gitea-api",
+ async (original) => ({
+ ...(await original<
+ typeof import("../../apps/api/src/plugins/gitea/utils/gitea-api")
+ >()),
+ createGiteaClient: () => provider,
+ }),
+);
+beforeEach(async () => {
+ await resetTestDatabase();
+ vi.clearAllMocks();
+});
+describe("github and gitea import permissions", () => {
+ it.each(["github", "gitea"])(
+ "%s denies a create-only custom role",
+ async (type) => {
+ const member = await createWorkspaceMember({ role: "importer" });
+ await db.insert(schema.workspaceRoleTable).values({
+ workspaceId: member.workspace.id,
+ role: "importer",
+ permission: JSON.stringify({ task: ["create"] }),
+ });
+ const { project } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+ const response = await app.request(
+ `/api/${type}-integration/import-issues`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ projectId: project.id }),
+ },
+ );
+ expect(response.status).toBe(403);
+ expect(provider.listIssues).not.toHaveBeenCalled();
+ },
+ );
+ it("gitea accepts a custom role with both create and update", async () => {
+ const member = await createWorkspaceMember({ role: "importer" });
+ await db.insert(schema.workspaceRoleTable).values({
+ workspaceId: member.workspace.id,
+ role: "importer",
+ permission: JSON.stringify({ task: ["create", "update"] }),
+ });
+ const { project } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ await db.insert(schema.integrationTable).values({
+ projectId: project.id,
+ type: "gitea",
+ config: JSON.stringify({
+ baseUrl: "https://gitea.example",
+ accessToken: "fake-test-token",
+ repositoryOwner: "owner",
+ repositoryName: "repo",
+ }),
+ });
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+ const response = await app.request("/api/gitea-integration/import-issues", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ projectId: project.id }),
+ });
+ expect(response.status).toBe(200);
+ expect(provider.listIssues).toHaveBeenCalled();
+ });
+});