From 0244ac2a84262c8ca899be5795abdab33708996d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 24 Jun 2025 17:21:06 -0400 Subject: [PATCH] feat: Allow allowIndexing and showLastUpdated to be set in shares.create endpoint (#9476) --- server/routes/api/shares/schema.ts | 2 ++ server/routes/api/shares/shares.test.ts | 23 +++++++++++++++++++++++ server/routes/api/shares/shares.ts | 12 ++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/server/routes/api/shares/schema.ts b/server/routes/api/shares/schema.ts index d17d944584..78532b9396 100644 --- a/server/routes/api/shares/schema.ts +++ b/server/routes/api/shares/schema.ts @@ -73,6 +73,8 @@ export const SharesCreateSchema = BaseSchema.extend({ message: "must be uuid or url slug", }), published: z.boolean().default(false), + allowIndexing: z.boolean().optional(), + showLastUpdated: z.boolean().optional(), urlId: z .string() .regex(UrlHelper.SHARE_URL_SLUG_REGEX, { diff --git a/server/routes/api/shares/shares.test.ts b/server/routes/api/shares/shares.test.ts index fe8b9f435a..6a793d3d76 100644 --- a/server/routes/api/shares/shares.test.ts +++ b/server/routes/api/shares/shares.test.ts @@ -302,6 +302,29 @@ describe("#shares.create", () => { expect(body.data.documentTitle).toBe(document.title); }); + it("should accept allowIndexing and showLastUpdated parameters", async () => { + const user = await buildUser(); + const document = await buildDocument({ + userId: user.id, + teamId: user.teamId, + }); + const res = await server.post("/api/shares.create", { + body: { + token: user.getJwtToken(), + documentId: document.id, + published: true, + allowIndexing: false, + showLastUpdated: true, + }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data.published).toBe(true); + expect(body.data.allowIndexing).toBe(false); + expect(body.data.showLastUpdated).toBe(true); + expect(body.data.documentTitle).toBe(document.title); + }); + it("should fail creating a share record with read-only permissions and publishing", async () => { const team = await buildTeam(); const user = await buildUser({ teamId: team.id }); diff --git a/server/routes/api/shares/shares.ts b/server/routes/api/shares/shares.ts index 9c20c38be4..b7a32370bb 100644 --- a/server/routes/api/shares/shares.ts +++ b/server/routes/api/shares/shares.ts @@ -187,8 +187,14 @@ router.post( validate(T.SharesCreateSchema), transaction(), async (ctx: APIContext) => { - const { documentId, published, urlId, includeChildDocuments } = - ctx.input.body; + const { + documentId, + published, + urlId, + includeChildDocuments, + allowIndexing, + showLastUpdated, + } = ctx.input.body; const { user } = ctx.state.auth; authorize(user, "createShare", user.team); @@ -214,6 +220,8 @@ router.post( userId: user.id, published, includeChildDocuments, + allowIndexing, + showLastUpdated, urlId, }, });