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(api): preserve ineligible assignee ID precedence

Tin62bcf3af0cbb
diff --git a/apps/api/src/task/resolve-import-assignees.ts b/apps/api/src/task/resolve-import-assignees.ts
index bd3fe213c..68d552cc3 100644
--- a/apps/api/src/task/resolve-import-assignees.ts
+++ b/apps/api/src/task/resolve-import-assignees.ts
@@ -25,17 +25,20 @@ export async function resolveImportAssignees(
instanceAdminRoleSql(schema.userTable.role),
);
const idUsers = await db
- .select({ id: schema.userTable.id })
+ .select({ id: schema.userTable.id, eligible: sql<boolean>`${eligible}` })
.from(schema.userTable)
- .where(and(inArray(schema.userTable.id, references), eligible));
- for (const user of idUsers) resolved.set(user.id, user.id);
+ .where(inArray(schema.userTable.id, references));
+ const existingIds = new Set(idUsers.map((user) => user.id));
+ for (const user of idUsers) {
+ if (user.eligible) resolved.set(user.id, user.id);
+ }
// Keep existing ID imports on the indexed path, including missing IDs.
const emails = [
...new Set(
references
.filter(
- (reference) => !resolved.has(reference) && reference.includes("@"),
+ (reference) => !existingIds.has(reference) && reference.includes("@"),
)
.map((reference) => reference.toLowerCase()),
),
@@ -56,8 +59,8 @@ export async function resolveImportAssignees(
byEmail.set(email, matches);
}
for (const reference of references) {
- // IDs keep precedence even when they resemble another user's email.
- if (resolved.has(reference)) continue;
+ // Existing IDs keep precedence even when their users are ineligible.
+ if (existingIds.has(reference)) continue;
const matches = byEmail.get(reference.toLowerCase());
if (matches?.size !== 1) continue;
const [id] = matches;
diff --git a/tests/api-integration/task-import-assignees.test.ts b/tests/api-integration/task-import-assignees.test.ts
index 89eebc621..5f8c00405 100644
--- a/tests/api-integration/task-import-assignees.test.ts
+++ b/tests/api-integration/task-import-assignees.test.ts
@@ -104,6 +104,42 @@ describe("JSON import assignees", () => {
).toEqual([idHolder.id, user.id]);
});
+ it("rejects an ineligible user ID instead of resolving another user's matching email", async () => {
+ const { user, project, importUsers } = await fixture();
+ await db.insert(schema.userTable).values({
+ id: user.email,
+ email: `${user.id}@nonmember.example.com`,
+ emailVerified: true,
+ name: "Nonmember ID Holder",
+ });
+ const result = await importUsers([
+ user.email,
+ user.email.toUpperCase(),
+ user.id,
+ ]);
+ expect(result.results.successful).toBe(2);
+ expect(result.results.failed).toBe(1);
+ expect(result.results.tasks[0]).toMatchObject({
+ success: false,
+ error: "Assignee is not a member of this workspace",
+ });
+ for (const index of [1, 2]) {
+ expect(result.results.tasks[index]).toMatchObject({
+ success: true,
+ task: { userId: user.id },
+ });
+ }
+ const tasks = await db
+ .select()
+ .from(schema.taskTable)
+ .where(eq(schema.taskTable.projectId, project.id));
+ expect(tasks.map((task) => task.title).sort()).toEqual([
+ "Task 1",
+ "Task 2",
+ ]);
+ expect(tasks.every((task) => task.userId === user.id)).toBe(true);
+ });
+
it("keeps indexed ID-only imports free of email scans", async () => {
const { user, workspace } = await fixture();
const queries = vi.spyOn(getDatabasePool(), "query");