Skip to content

Commit

Permalink
fix: Policies missing on documents.viewed endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor committed Aug 4, 2021
1 parent dad21b2 commit f2f550e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/api/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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",
},
],
},
],
Expand Down
1 change: 1 addition & 0 deletions server/api/documents.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit f2f550e

Please sign in to comment.