fix: documents.search API does not work with custom search slug

This commit is contained in:
Tom Moor
2024-01-20 22:58:37 -05:00
parent 4e8fe75368
commit cbb00c4871
2 changed files with 16 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
import { faker } from "@faker-js/faker";
import { addMinutes, subDays } from "date-fns"; import { addMinutes, subDays } from "date-fns";
import { CollectionPermission } from "@shared/types"; import { CollectionPermission } from "@shared/types";
import { import {
@@ -1232,28 +1233,35 @@ describe("#documents.search", () => {
}); });
it("should return results using shareId", async () => { it("should return results using shareId", async () => {
const subdomain = faker.internet.domainWord();
const team = await buildTeam({ subdomain });
const findableDocument = await buildDocument({ const findableDocument = await buildDocument({
title: "search term", title: "search term",
text: "random text", text: "random text",
teamId: team.id,
}); });
await buildDocument({ await buildDocument({
title: "search term", title: "search term",
text: "should not be found", text: "should not be found",
userId: findableDocument.createdById, userId: findableDocument.createdById,
teamId: findableDocument.teamId, teamId: team.id,
}); });
const share = await buildShare({ const share = await buildShare({
includeChildDocuments: true, includeChildDocuments: true,
documentId: findableDocument.id, documentId: findableDocument.id,
teamId: findableDocument.teamId, teamId: team.id,
urlId: "abc123",
}); });
const res = await server.post("/api/documents.search", { const res = await server.post("/api/documents.search", {
body: { body: {
query: "search term", query: "search term",
shareId: share.id, shareId: "abc123",
},
headers: {
host: `${subdomain}.outline.dev`,
}, },
}); });

View File

@@ -791,15 +791,18 @@ router.post(
let teamId; let teamId;
let response; let response;
let share;
if (shareId) { if (shareId) {
const teamFromCtx = await getTeamFromContext(ctx); const teamFromCtx = await getTeamFromContext(ctx);
const { share, document } = await documentLoader({ const { document, ...loaded } = await documentLoader({
teamId: teamFromCtx?.id, teamId: teamFromCtx?.id,
shareId, shareId,
user, user,
}); });
share = loaded.share;
if (!share?.includeChildDocuments) { if (!share?.includeChildDocuments) {
throw InvalidRequestError("Child documents cannot be searched"); throw InvalidRequestError("Child documents cannot be searched");
} }
@@ -868,7 +871,7 @@ router.post(
await SearchQuery.create({ await SearchQuery.create({
userId: user?.id, userId: user?.id,
teamId, teamId,
shareId, shareId: share?.id,
source: ctx.state.auth.type || "app", // we'll consider anything that isn't "api" to be "app" source: ctx.state.auth.type || "app", // we'll consider anything that isn't "api" to be "app"
query, query,
results: totalCount, results: totalCount,