diff --git a/app/scenes/Home.tsx b/app/scenes/Home.tsx index f79799b7e8..cd76f6b209 100644 --- a/app/scenes/Home.tsx +++ b/app/scenes/Home.tsx @@ -140,7 +140,9 @@ function Home() { documents={documents.createdByUser(userId)} fetch={documents.fetchOwned} options={{ - userId, + filters: [ + { field: "createdById", operator: "eq", value: userId }, + ], }} empty={ {t("You haven’t created any documents yet")} diff --git a/server/routes/api/documents/documents.test.ts b/server/routes/api/documents/documents.test.ts index 43055b160c..2d50a73e6a 100644 --- a/server/routes/api/documents/documents.test.ts +++ b/server/routes/api/documents/documents.test.ts @@ -1381,6 +1381,42 @@ describe("#documents.list", () => { expect(body.data).toHaveLength(2); }); + it("should match documents created by a user, excluding collaborations", async () => { + const user = await buildUser(); + const otherUser = await buildUser({ teamId: user.teamId }); + const created = await buildDocument({ + userId: user.id, + teamId: user.teamId, + }); + const collaborated = await buildDocument({ + userId: otherUser.id, + teamId: user.teamId, + }); + collaborated.lastModifiedById = user.id; + await collaborated.save(); + expect(collaborated.collaboratorIds).toContain(user.id); + + const res = await server.post("/api/documents.list", user, { + body: { + filters: [{ field: "createdById", operator: "eq", value: user.id }], + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + const ids = body.data.map((d: { id: string }) => d.id); + expect(ids).toEqual([created.id]); + }); + + it("should reject unsupported operators for createdById", async () => { + const user = await buildUser(); + const res = await server.post("/api/documents.list", user, { + body: { + filters: [{ field: "createdById", operator: "isNotNull" }], + }, + }); + expect(res.status).toEqual(400); + }); + it("should reject an unknown field", async () => { const user = await buildUser(); const res = await server.post("/api/documents.list", user, { diff --git a/server/routes/api/documents/schema.ts b/server/routes/api/documents/schema.ts index 40f78e16da..87dadcfe6a 100644 --- a/server/routes/api/documents/schema.ts +++ b/server/routes/api/documents/schema.ts @@ -23,6 +23,7 @@ const documentFilterFields = { title: "string", templateId: "uuid", collectionId: "uuid", + createdById: { kind: "uuid", operators: ["eq", "in"] }, // `userId` maps to the collaboratorIds array column and only supports // membership checks. userId: { kind: "uuid", operators: ["eq", "in"] },