From f2f550e1d2cc7b316f3caf3b546a7c76e0f7df7d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 3 Aug 2021 20:02:11 -0700 Subject: [PATCH] fix: Policies missing on documents.viewed endpoint --- server/api/documents.js | 12 ++++++++++-- server/api/documents.test.js | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/server/api/documents.js b/server/api/documents.js index 58b86e6b6..faa9bf25f 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -310,9 +310,10 @@ router.post("documents.viewed", auth(), pagination(), async (ctx) => { const user = ctx.state.user; const collectionIds = await user.collectionIds(); + const userId = user.id; const views = await View.findAll({ - where: { userId: user.id }, + where: { userId }, order: [[sort, direction]], include: [ { @@ -325,9 +326,16 @@ router.post("documents.viewed", auth(), pagination(), async (ctx) => { { model: Star, as: "starred", - where: { userId: user.id }, + where: { userId }, + separate: true, required: false, }, + { + model: Collection.scope({ + method: ["withMembership", userId], + }), + as: "collection", + }, ], }, ], diff --git a/server/api/documents.test.js b/server/api/documents.test.js index 1f6413a9e..e43609d62 100644 --- a/server/api/documents.test.js +++ b/server/api/documents.test.js @@ -1349,6 +1349,7 @@ describe("#documents.viewed", () => { expect(res.status).toEqual(200); expect(body.data.length).toEqual(1); expect(body.data[0].id).toEqual(document.id); + expect(body.policies[0].abilities.update).toEqual(true); }); it("should not return recently viewed but deleted documents", async () => {