mirror of
https://github.com/outline/outline.git
synced 2026-12-05 18:55:10 +03:00
fix: documents.drafts collectionId filter includes unfiled drafts (#14772)
This commit is contained in:
1 parent
0d80559f8d
commit
66254a8239
2 files changed
+34
-6
No files matched your search
@@ -2944,6 +2944,32 @@ describe("#documents.drafts", () => {
|
||||
expect(body.data.length).toEqual(drafts.length);
|
||||
});
|
||||
|
||||
it("should only return drafts in the given collection", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const document = await buildDraftDocument({
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
await buildDraftDocument({
|
||||
userId: user.id,
|
||||
collectionId: null,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
|
||||
const res = await server.post("/api/documents.drafts", user, {
|
||||
body: { collectionId: collection.id },
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.length).toEqual(1);
|
||||
expect(body.data[0].id).toEqual(document.id);
|
||||
});
|
||||
|
||||
it("should not return drafts in private collections not a member of", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
|
||||
@@ -662,15 +662,17 @@ router.post(
|
||||
authorize(user, "readDocument", collection);
|
||||
}
|
||||
|
||||
const collectionIds = collectionId
|
||||
? [collectionId]
|
||||
: await user.collectionIds();
|
||||
const where: WhereOptions = {
|
||||
teamId: user.teamId,
|
||||
createdById: user.id,
|
||||
collectionId: {
|
||||
[Op.or]: [{ [Op.in]: collectionIds }, { [Op.is]: null }],
|
||||
},
|
||||
collectionId: collectionId
|
||||
? collectionId
|
||||
: {
|
||||
[Op.or]: [
|
||||
{ [Op.in]: await user.collectionIds() },
|
||||
{ [Op.is]: null },
|
||||
],
|
||||
},
|
||||
publishedAt: {
|
||||
[Op.is]: null,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user