fix: Respect collectionId filter in documents.list backlink requests (#14779)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-11-27 09:14:19 -05:00
1 parent a09c77a4f7
commit 9b18f62fd0
2 files changed
+46 -4

No files matched your search

@@ -1485,6 +1485,51 @@ describe("#documents.list", () => {
expect(body.data[0].id).toEqual(anotherDoc.id);
});
it("should filter backlinks by collectionId", async () => {
const user = await buildUser();
const document = await buildDocument({
userId: user.id,
teamId: user.teamId,
});
const collection = await buildCollection({
userId: user.id,
teamId: user.teamId,
});
const otherCollection = await buildCollection({
userId: user.id,
teamId: user.teamId,
});
const inCollection = await buildDocument({
userId: user.id,
teamId: user.teamId,
collectionId: collection.id,
});
const inOtherCollection = await buildDocument({
userId: user.id,
teamId: user.teamId,
collectionId: otherCollection.id,
});
await Relationship.bulkCreate(
[inCollection, inOtherCollection].map((source) => ({
reverseDocumentId: source.id,
type: RelationshipType.Backlink,
documentId: document.id,
userId: user.id,
}))
);
const res = await server.post("/api/documents.list", user, {
body: {
backlinkDocumentId: document.id,
collectionId: collection.id,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.map((doc: { id: string }) => doc.id)).toEqual([
inCollection.id,
]);
});
describe("filter DSL", () => {
it("should match a simple contains leaf case-insensitively", async () => {
const user = await buildUser();
+1 -4
View File
@@ -4,7 +4,7 @@ import fs from "fs-extra";
import invariant from "invariant";
import contentDisposition from "content-disposition";
import Router from "@koa/router";
import { escapeRegExp, has, remove, uniq } from "es-toolkit/compat";
import { escapeRegExp, uniq } from "es-toolkit/compat";
import mime from "mime-types";
import type { Order, ScopeOptions, WhereOptions } from "sequelize";
import type { Filter } from "@shared/helpers/FilterHelper";
@@ -331,9 +331,6 @@ router.post(
);
where[Op.and].push({ id: sourceDocumentIds });
// For safety, ensure the collectionId is not set in the query.
remove(where[Op.and], (cond) => has(cond, "collectionId"));
}
// A filter referencing publishedAt can surface drafts (the replacement